Menu

#335 BeanShell assumes it wasnt loaded by boot classloader, fails

None
closed
nobody
General (151)
5
2018-08-02
2010-11-24
arshan
No

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.

Discussion

  • nickl-

    nickl- - 2018-08-02
    • status: open --> closed
    • Group: -->
     
  • nickl-

    nickl- - 2018-08-02

    Ticket has been migrated to github.
    Please follow up on this over here: https://github.com/beanshell/beanshell/issues/473

     

Log in to post a comment.