Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using JSR-223, exception is thrown for clause that shouldn't be evaluated #60

Closed
GoogleCodeExporter opened this issue Apr 22, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
    public static void main(String[] args) {

        String script = "String foo=null; if (foo!=null && foo.length()>0) System.out.println(\"bar\")";

        System.out.print("Using script engine: ");
        try {
            new ScriptEngineManager().getEngineByName("beanshell").eval(script);
        } catch (ScriptException e) {
            System.out.println(e.getMessage());
        }

        System.out.print("\nUsing interpreter: ");
        try {
            new Interpreter().eval(script);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

What is the expected output? What do you see instead?
Since foo==null, i would not expect foo.length to be evaluated; this 
expectation is met by the direct Bsh interpreter but not by the ScriptEngine. 
Here's the output:
Using script engine: bsh.EvalError: Sourced file: inline evaluation of: 
``String foo=null; if (foo!=null && foo.length()>0) 
System.out.println("bar");'' : Attempt to resolve method: length() on undefined 
variable or class name: foo : at Line: 1 : in file: inline evaluation of: 
``String foo=null; if (foo!=null && foo.length()>0) 
System.out.println("bar");'' : foo .length ( ) 
 in inline evaluation of: ``String foo=null; if (foo!=null && foo.length()>0) System.out.println("bar");'' at line number 1

Using interpreter: 

What version of the product are you using? On what operating system?
bsh-2.1b4 on windows xp

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 11 Nov 2011 at 7:12

@GoogleCodeExporter
Copy link
Author

The bsh.BshScriptEngine just delegates to the interpreter.
You are getting the NPE because

    new ScriptEngineManager().getEngineByName("beanshell")

evaluates to <null>.
Nevertheless, I can't reproduce this. 
Could you verify that your jar is correct and contains a file 
"META-INF/services/javax.script.ScriptEngineFactory"? If not you may run into 
issue#43
http://code.google.com/p/beanshell2/issues/detail?id=43
Did you build the jar on your own? You must not use ant 1.7 to build..

Original comment by [email protected] on 12 Nov 2011 at 3:51

  • Changed state: Invalid

@GoogleCodeExporter
Copy link
Author

Thanks for taking a look, but i'm still having the issue.
i'm using the 2.1b4 jarfile which contains the javax.script.ScriptEngineFactory.
i did not build my own jar.
note that the exception is not an NPE, but a complaint about foo being unknown.
the exception occurs only when foo is null.

Original comment by [email protected] on 14 Nov 2011 at 5:59

@GoogleCodeExporter
Copy link
Author

note: in addition to delegating to an interpreter, the ScriptingEngine calls 
setNameSpace() which may be causing the issue.

Original comment by [email protected] on 14 Nov 2011 at 9:32

@GoogleCodeExporter
Copy link
Author

Ok, i drilled down the problem again. It's a duplicate to issue#55 which is 
already fixed in trunk and branch v2.1. So the fix will be included in the next 
version 2.1b5.

Original comment by [email protected] on 16 Nov 2011 at 9:26

  • Changed state: Duplicate

nickl- added a commit to beanshell/beanshell that referenced this issue Nov 8, 2017
Merge pejobo/beanshell2@9e6ed9e test for issue pejobo/beanshell2#60 JSR-223, exception is thrown for clause that shouldn't be evaluated
nickl- added a commit to beanshell/beanshell that referenced this issue Jan 7, 2019
Merge pejobo/beanshell2@9e6ed9e test for issue pejobo/beanshell2#60 JSR-223, exception is thrown for clause that shouldn't be evaluated
nickl- added a commit to beanshell/beanshell that referenced this issue Jan 7, 2019
Merge pejobo/beanshell2@9e6ed9e test for issue pejobo/beanshell2#60 JSR-223, exception is thrown for clause that shouldn't be evaluated
nickl- added a commit to beanshell/beanshell that referenced this issue Mar 19, 2019
Merge pejobo/beanshell2@9e6ed9e test for issue pejobo/beanshell2#60 JSR-223, exception is thrown for clause that shouldn't be evaluated
patniemeyer pushed a commit to beanshell/beanshell that referenced this issue Dec 6, 2023
Merge pejobo/beanshell2@9e6ed9e test for issue pejobo/beanshell2#60 JSR-223, exception is thrown for clause that shouldn't be evaluated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant