#221 Runtime error using forward referrence

open
nobody
None
5
2005-06-15
2005-06-15
Nigel
No

> cat t5.java
public class t5{
static String f = myForwardRef();

static String myForwardRef(){
return ("Nigel is best");
}
public static void main (String[] args){
System.out.println(f);
}
}
Process cat exited with code 0

Java produces the familiar:
> javac t5.java
Process javac exited with code 0
> java t5
Nigel is best
Process java exited with code 0

BeanShell will do anything to avoid saying it:
> java -classpath ../../bsh-2.0b4.jar bsh.Interpreter
t5.java
Script threw exception: Sourced file: t5.java : Typed
variable declaration : Exception invoking imported object
method. : at Line: 2 : in file: t5.java : myForwardRef ( )

Target exception:
java.lang.reflect.InvocationTargetException

java.lang.reflect.InvocationTargetException
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke
(Method.java:585)
at bsh.Reflect.invokeMethod(Unknown
Source)
at bsh.BshMethod.invoke(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bsh.Name.invokeLocalMethod(Unknown
Source)
at bsh.Name.invokeMethod(Unknown Source)
at bsh.BSHMethodInvocation.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHPrimaryExpression.eval(Unknown
Source)
at bsh.BSHVariableDeclarator.eval(Unknown
Source)
at bsh.BSHTypedVariableDeclaration.eval
(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown
Source)
at
bsh.ClassGeneratorImpl.generateClassImpl(Unknown
Source)
at bsh.ClassGeneratorImpl.generateClass
(Unknown Source)
at bsh.BSHClassDeclaration.eval(Unknown
Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.source(Unknown Source)
at bsh.Interpreter.main(Unknown Source)
Caused by: java.lang.NullPointerException
at t5.myForwardRef(BeanShell Generated via
ASM (www.objectweb.org))
... 21 more
Process java exited with code 0

Discussion


Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks