cbuschka / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

BeanShell assumes it wasnt loaded by boot classloader, fails - ID: 3117777 #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Copied from 
https://sourceforge.net/tracker/?func=detail&aid=3117777&group_id=4075&atid=1040
75

If the BeanShell jar is loaded by the boot class loader (which will happen with 
its use in Xbootclasspath or with Java agents), the bsh.Interpreter constructor 
will blow up with the following NPE:

Exception in thread "Thread-13" java.lang.NullPointerException
at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)
at bsh.NameSpace.classForName(Unknown Source)
at bsh.NameSpace.getClassImpl(Unknown Source)
at bsh.NameSpace.getClass(Unknown Source)
at bsh.Name.consumeNextObjectField(Unknown Source)
at bsh.Name.toObject(Unknown Source)
at bsh.Name.toObject(Unknown Source)
at bsh.NameSpace.get(Unknown Source)
at bsh.Interpreter.get(Unknown Source)
at bsh.Interpreter.getu(Unknown Source)
at bsh.Interpreter.<init>(Unknown Source)
at bsh.Interpreter.<init>(Unknown Source)
at bsh.Interpreter.<init>(Unknown Source)
at com.my.code.Class.java:387)

This is because of the following code from ClassManagerImpl.java (unknown line) 
from classForName():

if ( name.startsWith( BSH_PACKAGE ) )
try {
c = Interpreter.class.getClassLoader().loadClass( name );
} catch ( ClassNotFoundException e ) {}

If the Interpreter class, along with the rest of bsh is loaded from the boot 
class loader, the getClassLoader() call will return null, and the loadClass() 
call will cause an NPE. Sorry that I don't have time to suggest a proper fix or 
provide a proper unit test. Maybe replacing the call with a Thread context 
class loader if the class loader is found to be null.

Original issue reported on code.google.com by pejob...@gmail.com on 25 Feb 2011 at 5:27

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r63.

Original comment by pejob...@gmail.com on 25 Feb 2011 at 5:42

GoogleCodeExporter commented 8 years ago

Original comment by pejob...@gmail.com on 25 Feb 2011 at 5:53

GoogleCodeExporter commented 8 years ago

Original comment by pejob...@gmail.com on 20 Oct 2011 at 7:12