Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Xamarin.Android.Tools.Bytecode/AttributeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ public string InnerName {
}
}

public string OuterClassName => OuterClass?.Name?.Value;

public override string ToString ()
{
return string.Format ("InnerClass(InnerClass='{0}', OuterClass='{1}', InnerName='{2}', InnerClassAccessFlags={3})",
Expand Down
37 changes: 31 additions & 6 deletions src/Xamarin.Android.Tools.Bytecode/ClassPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ public ClassPath (string path = null)
Load (path);
}

public void Load (string jarFile)
public void Load (string filePath)
{
if (!IsJarFile (jarFile))
throw new ArgumentException ("'jarFile' is not a valid .jar file.", "jarFile");

using (var jarStream = File.OpenRead (jarFile)) {
Load (jarStream);
if (IsJmodFile (filePath)) {
Comment thread
jpobst marked this conversation as resolved.
using (var source = File.OpenRead (filePath)) {
var slice = new PartialStream (source, 4);
Load (slice);
}
return;
}
if (IsJarFile (filePath)) {
using (var jarStream = File.OpenRead (filePath)) {
Load (jarStream);
}
return;
}
throw new ArgumentException ($"`{filePath}` is not a supported file format.", nameof (filePath));
}

public void Load (Stream jarStream, bool leaveOpen = false)
Expand Down Expand Up @@ -113,6 +121,23 @@ public static bool IsJarFile (string jarFile)
}
}

public static bool IsJmodFile (string jmodFile)
{
if (jmodFile == null)
throw new ArgumentNullException (nameof (jmodFile));
try {
var f = File.OpenRead (jmodFile);
var h = new byte[4];
if (f.Read (h, 0, h.Length) != 4) {
return false;
}
return h[0] == 0x4a && h[1] == 0x4d && h[2] == 0x01 && h[3] == 0x00;
}
catch (Exception) {
return false;
}
}

XAttribute GetApiSource ()
{
if (string.IsNullOrEmpty (ApiSource))
Expand Down
8 changes: 8 additions & 0 deletions src/Xamarin.Android.Tools.Bytecode/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static void Warning (int verbosity, string format, params object[] args)
log (TraceLevel.Warning, verbosity, format, args);
}

public static void Warning (int verbosity, string message) => Warning (verbosity, "{0}", message);

public static void Error (string format, params object[] args)
{
var log = OnLog;
Expand All @@ -23,6 +25,8 @@ public static void Error (string format, params object[] args)
log (TraceLevel.Error, 0, format, args);
}

public static void Error (string message) => Error ("{0}", message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these do? These should be equivalent:

public static void Error (string format, params object[] args)
public static void Error (string message)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpobst: these overloads preserve sanity. :-)

What do you expect to happen with:

Console.WriteLine("{foo}");

What happens -- which I hope is what you expect? -- is that {foo} is written to stdout.

What happens if you call Log.Error ("{foo}"), prior to this change?

You get a System.FormatException, by way of `string.Format()!

string.Format("{foo}");                                                                                                                                                                               
System.FormatException: Input string was not in a correct format.                                                                                                                                               
  at System.Text.StringBuilder.AppendFormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args)
  at System.String.FormatHelper (System.IFormatProvider provider, System.String format, System.ParamsArray args)
  at System.String.Format (System.String format, System.Object[] args)
  at <InteractiveExpressionClass>.Host (System.Object& $retval)
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set)

See also: https://github.com/xamarin/monodroid/commit/c75aaaad56ef27bb907ad59a61aab4a741468dfe

The TL/DR: is that providing only a (string format, params object[]) method signature is a recipe for disaster, especially as we continue migrating to C#6 $"..." format strings.


public static void Message (string format, params object[] args)
{
var log = OnLog;
Expand All @@ -31,13 +35,17 @@ public static void Message (string format, params object[] args)
log (TraceLevel.Info, 0, format, args);
}

public static void Message (string message) => Message ("{0}", message);

public static void Debug (string format, params object[] args)
{
var log = OnLog;
if (log == null)
return;
log (TraceLevel.Verbose, 0, format, args);
}

public static void Debug (string message) => Debug ("{0}", message);
}
}

Loading