jsr-223 error evaluating script when a variable is set to null

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

jsr-223 error evaluating script when a variable is set to null

etanster
i had been using bsh 2.0b4 with java 5.
after migrating to java6, i decided to experiment with the scripting interface.
Using bsh-2.1b4.jar and this small program, i got the error below.
There are two points i don't understand:
a) the error message complains about s being undefined. but it is clearly defined as String.
b) since s==null, the expression s.length()>0 should not be evaluated at all.
Any help would be appreciated.
----------------------------------------------
import javax.script.*;
 
public class TestNull {
        public static void main(String[] args) {
                String script = "String s=null; if (s!=null && s.length()>0) ;";
 
                try {
                        new ScriptEngineManager().getEngineByName("bsh").eval(script);
                } catch (ScriptException e) {
                        System.out.println(e.getMessage());
                }
        }
}
------------------------------------------
bsh.EvalError: Sourced file: inline evaluation of: ``String s=null; if (s!=null && s.length()>0) ;'' : Attempt to resolve method: length() on undefined variable or class name: s : at Line: 1 : in file: inline evaluation of: ``String s=null; if (s!=null && s.length()>0) ;'' : s .length ( )
 in inline evaluation of: ``String s=null; if (s!=null && s.length()>0) ;'' at line number 1