eobermuhlner / jshell-scriptengine

JShell script engine for Java (JSR-223 compatible)
MIT License
32 stars 8 forks source link

npe on setup that works with nashorn js engine #6

Open garth0jsonar opened 3 years ago

garth0jsonar commented 3 years ago

evaluating this:

var foo="dfsf";

I get this:

00:07:19.969 AWT-EventQueue-0 UtilSwing.eval: rt ex=java.lang.NullPointerException
java.lang.NullPointerException
    at ch.obermuhlner.scriptengine.jshell.JShellCompiledScript.setBindingsValue(JShellCompiledScript.java:84)

this is because global bindings are null there:

        if (!engineBindings.containsKey(name) && globalBindings.containsKey(name)) {

1.1.0 , latest adopt jdk 11. Suggest always init globalBindings.

garth0jsonar commented 3 years ago

In JShellCompiledScript (35):

        Bindings globalBindings = context.getBindings(ScriptContext.GLOBAL_SCOPE);

can return null.