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

GraalJSScriptEngine: NPE when setting empty engine bindings #839

Closed
simonis opened this issue Aug 29, 2024 · 1 comment · Fixed by #840
Closed

GraalJSScriptEngine: NPE when setting empty engine bindings #839

simonis opened this issue Aug 29, 2024 · 1 comment · Fixed by #840
Assignees
Labels
bug Something isn't working

Comments

@simonis
Copy link
Contributor

simonis commented Aug 29, 2024

When using the JSR-223 compliant ScriptEngine implementation, GraalJSScriptEngine will throw a NPE when setting empty bindings with ENGINE_SCOPE:

import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class EngineScopeBindingsNPE {

  public static void main(String[] args) {
    ScriptEngineManager engineManager = new ScriptEngineManager();
    ScriptEngine engine = engineManager.getEngineByName("graal.js");
    if (engine == null) {
      System.out.println("graal.js engine not found");
      return;
    }
    Bindings bindings = engine.createBindings();
    engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
    if (engine.getBindings(ScriptContext.ENGINE_SCOPE) != bindings) {
      throw new Error("Should be the same");
    }
  }
}

Executing this program will result in:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.graalvm.polyglot.Context.eval(org.graalvm.polyglot.Source)" because "context" is null
	at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.evalInternal(GraalJSScriptEngine.java:408)
	at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSBindings.updateBinding(GraalJSBindings.java:121)
	at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSBindings.updateContextBinding(GraalJSBindings.java:111)
	at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSBindings.updateEngineScriptContext(GraalJSBindings.java:222)
	at org.graalvm.js.scriptengine/com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.setBindings(GraalJSScriptEngine.java:426)
	at EngineScopeBindingsNPE.main(EngineScopeBindingsNPE.java:16)
@iamstolis
Copy link
Member

Thank you for the report and for the submission of the PR that fixes the issue!

simonis added a commit to simonis/graaljs that referenced this issue Sep 26, 2024
Fixes oracle#839

Cherry picked from:
69c6c87: GraalJSScriptEngine: NPE when setting empty engine bindings
16d63fa: Correction of the year in the copyright header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants