Skip to content

Commit e1aae8f

Browse files
jonpryoratsushieno
authored andcommitted
[class-parse] Support class-parse --dump on java.lang.Object (#108)
Running `class-parse --dump` on `java.lang.Object` would fail: # on macOS, JDK 1.8 installed $ unzip /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/rt.jar java/lang/Object.class $ mono class-parse.exe --dump java/lang/Object.class ... class-parse: Unable to read file 'java/lang/Object.class': Object reference not set to an instance of an object Enabling verbose output (`class-parse -v`) didn't help: $ mono class-parse.exe -v --dump java/lang/Object.class Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Mono.Options.Option.Parse[T] (System.String value, Mono.Options.OptionContext c) [0x0005e] in <4d78dd3d6bb745d7a994cb7587b83fb2>:0 ... Doh! The problem with the `IndexOutOfRangeException` is a bug in `Mono.Options-PCL.cs`: it should be using `GenericTypeArguments[0]`, *not* `GenericTypeParameters[0]`. Fix that. Once that is fixed, we see that the `NullReferenceException` is coming from accessing `ClassFile.SuperClass.Name`, because `java.lang.Object` *has no superclass*, and thus `ClassFile.SuperClass` returns `null`. Properly check for that. With those changes in place, `class-parse --dump java.lang.Object` works as intended: $ mono class-parse.exe --dump java/lang/Object.class .class version: 52.0 ... Methods Count: 12 ... 11: finalize ()V Protected Code(10, Unknown[LineNumberTable](6)) Exceptions(java/lang/Throwable)
1 parent 0f82b99 commit e1aae8f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

tools/class-parse/Mono.Options-PCL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ protected static T Parse<T> (string value, OptionContext c)
530530
bool nullable = ti.IsValueType && ti.IsGenericType &&
531531
!ti.IsGenericTypeDefinition &&
532532
tt.GetGenericTypeDefinition () == typeof(Nullable<>);
533-
Type targetType = nullable ? tt.GetTypeInfo ().GenericTypeParameters [0] : typeof(T);
533+
Type targetType = nullable ? tt.GetTypeInfo ().GenericTypeArguments [0] : typeof(T);
534534
//TypeConverter conv = TypeDescriptor.GetConverter (targetType);
535535
T t = default (T);
536536
try {

tools/class-parse/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void DumpClassFile (string file, TextWriter output)
139139
output.WriteLine ("\t{0}: {1}", i, c.ConstantPool [i]);
140140
}
141141
output.WriteLine ("ThisClass: {0}", c.ThisClass.Name);
142-
output.WriteLine ("SuperClass: {0}", c.SuperClass.Name);
142+
output.WriteLine ("SuperClass: {0}", c.SuperClass?.Name);
143143
output.WriteLine ("AccessFlags: {0}", c.AccessFlags);
144144
output.WriteLine ("Attributes Count: {0}", c.Attributes.Count);
145145
for (int i = 0; i < c.Attributes.Count; ++i) {

0 commit comments

Comments
 (0)