Ignore permitted languages that aren't present in sandbox check
Consider following method:
private static void createContext(SandboxPolicy policy) {
Context.newBuilder("myMissingLang") // myMissingLang is not present
.sandbox(policy)
.in(InputStream.nullInputStream())
.out(OutputStream.nullOutputStream())
.err(OutputStream.nullOutputStream())
.build();
}
Running createContext(SandboxPolicy.TRUSTED) will run without exceptions, while createContext(SandboxPolicy.CONSTRAINED) currently throws the following exception:
Exception in thread "main" org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException: Cannot invoke "com.oracle.truffle.polyglot.PolyglotLanguage.validateSandbox(org.graalvm.polyglot.SandboxPolicy)" because the return value of "java.util.Map.get(Object)" is null
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.validateSandbox(PolyglotEngineImpl.java:2209)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:339)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:283)
at com.oracle.graal.graal_enterprise/com.oracle.truffle.polyglot.enterprise.EnterprisePolyglotImpl.buildEngine(stripped:136)
at org.graalvm.sdk/org.graalvm.polyglot.Engine$Builder.build(Engine.java:681)
at org.graalvm.sdk/org.graalvm.polyglot.Context$Builder.build(Context.java:1926)
This PR avoids the NPE by ignoring entries in the permittedLanguages array that don't have a matching language installed. This way, the behavior is the same for all sandbox policies.
Thank you for contributing to GraalVM, @chumer can you please assign someone to review this PR?
Tests for this are needed in SandboxPolicyTest. But we can take it from here. Thank you for the report! cc @tzezula
Please let me know if there is something to do from my side. Thanks!
@SirYwell sorry for the delay. We are currently very busy, but we can hopefully pick this up soon. I assume this is not a blocker for you, right?
@SirYwell sorry for the delay. We are currently very busy, but we can hopefully pick this up soon. I assume this is not a blocker for you, right?
That's totally fine! I just wanted to make sure there's nothing to do from my side right now.
Any news on this?