#230 BeanShell's handling of java.lang.NullPointerException

open
nobody
None
5
2005-07-13
2005-07-13
Nigel
No

> cat t90.java
public class t90{
static String myProc(){
return "Nigel is best";
}
public static void main(String[] args){
String name = null;
System.out.println(name);
name = myProc();
System.out.println(name);
return;
}
}
Process cat exited with code 0

java produces the expected:

> javac t90.java
Process javac exited with code 0
> java t90
null
Nigel is best
Process java exited with code 0

whereas BeanShell is too aggressive:

> java -classpath bsh-2.0b5.jar bsh.Interpreter t90.java
Class: class t90 main method threw exception:Method
Invocation System.out.println : at Line: 7 : in file:
t90.java : System .out .println ( name )

Called from method: main : at Line: -1 : in file: <Called
from Java Code> : <Compiled Java Code>
Target exception: java.lang.NullPointerException

Process java exited with code 0

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks