"org.graalvm.polyglot.PolyglotException: ReferenceError: org is not defined" when using GraalVM and script based expressions

I am using v7.15 EE and am trying to use GraalVM for the scripting engine, but I get the following error when using script based conditions in my process:

Caused by: javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: ReferenceError: org is not defined
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException(GraalJSScriptEngine.java:483)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:460)
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426)
	at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
	at org.camunda.bpm.engine.impl.scripting.SourceExecutableScript.evaluateScript(SourceExecutableScript.java:125)
	at org.camunda.bpm.engine.impl.scripting.SourceExecutableScript.evaluate(SourceExecutableScript.java:65)

I have a test process that replicates the problem, with the following script based condition:

I have included the following GraalVM dependencies in my pom.xml file:

<dependency>
    <groupId>org.graalvm.js</groupId>
    <artifactId>js</artifactId>
    <version>21.2.0</version>
</dependency>
<dependency>
    <groupId>org.graalvm.js</groupId>
    <artifactId>js-scriptengine</artifactId>
    <version>21.2.0</version>
</dependency>

So, is there any additional configuration I need to perform to configure GraalVM, or are my dependencies incorrect? Thanks in advance.

I have attached the full test process and POM file:

test.bpmn (4.3 KB)
pom.xml (6.4 KB)

OK, so I have tested the process against 7.16 alpha 4 and it works, so I guess that is the GraalVM support kicking in.

But if anyone has a solution for 7.15 that would also be great.

Hey @Justin_Phillips,

GraalVM JavaScript (GraalJS) is used through its ScriptEngine implementation in Camunda when you access it in scripts.

In case Spin is part of your project and the Spin process engine plugin is on the classpath, the plugin will try to initialize the JavaScript environment for your scripts with script format “javascript”. This includes providing Spin’s “S” function, which most probably leads to the exception you are seeing. This will also happen if you try to access Java types from your scripts yourself.

Why is that happening?
GraalJS is secure by default and does not allow access to host classes (like Spin’s “S” function) out of the box.

What can you do about it?
You have to allow host access (“allowHostAccess”) and host class lookup (“allowHostClassLookup”) in the GraalJS ScriptEngine.
The way we did this in 7.16 is by configuring GraalJS before a script is executed. You can try to do the same thing in your application.
If you cannot do that, you can either pass on system properties or enable Nashorn compatibility mode to achieve that.

Hope that helps.

Best,
Tobias

1 Like

Thanks, that is very helpful.