disassemble throws NPE with system classes
Jamison Hope
jrh@theptrgroup.com
Sat Oct 5 22:49:00 GMT 2013
Calling disassemble on system class methods like Math#asin or
Object#toString will currently throw a NPE (at least it will with Oracle
Java 1.7.0_40):
#|kawa:1|# (disassemble java.lang.Math:asin)
java.lang.NullPointerException
at gnu.expr.PrimProcedure.disassemble(PrimProcedure.java:1016)
at gnu.expr.PrimProcedure.disassemble(PrimProcedure.java:975)
at gnu.expr.PrimProcedure.disassemble$X(PrimProcedure.java:969)
at kawa.lib.trace.disassemble(trace.scm:22)
at atInteractiveLevel$73.run(stdin:74)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:309)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:210)
at kawa.Shell.run(Shell.java:279)
at kawa.Shell.run(Shell.java:194)
at kawa.Shell.run(Shell.java:175)
at kawa.repl.main(repl.java:871)
This happens because Class#getClassLoader() returns null to represent
the bootstrap class loader:
> Returns the class loader for the class. Some implementations may use
> null to represent the bootstrap class loader. This method will return
> null in such implementations if this class was loaded by the bootstrap
> class loader.
- http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getClassLoader()
Inserting a line
if (loader == null) loader = ClassLoader.getSystemClassLoader();
in PrimProcedure#disassemble(Procedure,ClassTypeWriter)
seems to fix it:
#|kawa:1|# (disassemble java.lang.Object:toString)
In class java.lang.Object at jar:file:/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/Object.class
Method name:"toString" public Signature: ()java.lang.String
Attribute "Code", length:60, max_stack:2, max_locals:1, code_length:36
[snip]
Patch attached.
--
Jamison Hope
The PTR Group
www.theptrgroup.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-disassemble-npe.diff
Type: application/octet-stream
Size: 1394 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/kawa/attachments/20131005/54d114d4/attachment.obj>
-------------- next part --------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://sourceware.org/pipermail/kawa/attachments/20131005/54d114d4/attachment.sig>
More information about the Kawa
mailing list