Skip to content

Conversation

@jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Dec 9, 2016

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)

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)
@atsushieno atsushieno merged commit e1aae8f into dotnet:master Dec 9, 2016
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants