#334 Nullpointer when Interpreter.DEBUG == TRUE

open
nobody
Parsing (77)
5
2014-08-16
2010-03-03
Anonymous
No

Hello,

I am using beanshell version 1.3.0 in DEBUG mode. In the java class bsh.Reflect I get an Nullpointer Exception when my method argument is NULL.
The Nullpointer occured in method invokeOnMethod.

--> Interpreter.debug("tmpArgs[" + k + "] = " + aobj1[k] + " type = " + aobj1[k].getClass()); // when aobj1[k] is null then getClass will cause the NullPointerException

Code:

private static Object invokeOnMethod(Method method, Object obj, Object aobj[])
throws ReflectError, InvocationTargetException
{
Object aobj1[];

....

aobj1 = new Object[aobj.length];
Class aclass[] = method.getParameterTypes();
try
{
for(int j = 0; j < aobj.length; j++)
{
aobj1[j] = NameSpace.getAssignableForm(aobj[j], aclass[j]);
}

}
catch(UtilEvalError utilevalerror)
{
throw new InterpreterError("illegal argument type in method invocation: " + utilevalerror);
}
aobj1 = unwrapPrimitives(aobj1);
if(Interpreter.DEBUG)
{
Interpreter.debug("Invoking method (after massaging values): " + method + " with tmpArgs:");
for(int k = 0; k < aobj1.length; k++)
{
Interpreter.debug("tmpArgs[" + k + "] = " + aobj1[k] + " type = " + aobj1[k].getClass()); // when aobj1[k] is null then getClass will cause the NullPointerException
}

}
....

Maybe it is possible to get a patch for release 1.3.0 that fixes this error?

Kind regards,

Marco.

Discussion


  • Anonymous
    2011-02-27

    Don't get the point here:

    > when aobj1[k] is null then getClass will cause the NullPointerException

    This is your code so you are responsible for preventing this NPE.

    Nevertheless you could give the BeanShell fork (BeanShell2) a try: Look at at http://code.google.com/p/beanshell2
    Dowonload it here: http://beanshell2.googlecode.com/files/bsh-2.1b0.jar