Script Engine is not working for evaluating javascript code from Camunda 8 Script task

In my bpmn flow, camunda 8 script task



          <zeebe:header key="language" value="javascript" />

          <zeebe:header **key**="script" **value**="var firstName = &#34;John&#34;; var lastName = &#34;Doe&#34;; var age = 30; var message = &#34;Hello, my name is &#34; + firstName + &#34; &#34; + lastName + &#34; and I am &#34; + age + &#34; years old.&#34;;  console.log(message);" />


In Java,

	@ZeebeWorker(type = "script", name = "scriptJobWorker", autoComplete = true)
	public void script(final JobClient jobClient, final ActivatedJob job) throws InterruptedException {

		Object x = job.getVariablesAsMap().get("x");
		String script = job.getCustomHeaders().get("script");
		if (script != null && job.getCustomHeaders().get("language") != null) {
			// Execute the script using GroovyShell
			Object result = **evaluateJavaScript**(script);
			client.newSetVariablesCommand(job.getProcessInstanceKey()).variables(Map.of("result", result)).send().join();
		} else {
			// Handle missing script or language
			System.out.println("Script or language is missing in job headers");

 **private Object evaluateJavaScript(String script) {**
         // Create a new JavaScript engine manager
         ScriptEngineManager manager = new ScriptEngineManager();

         // Get the JavaScript engine
         ScriptEngine engine = manager.getEngineByName("javascript");
         System.out.println("Engine name: "+engine);

         try {
             // Evaluate the script and return the result
             return engine.eval(script);
         } catch (ScriptException e) {
             return null;


var firstName = "John"; var lastName = "Doe"; var age = 30; var message = "Hello, my name is " + firstName + " " + lastName + " and I am " + age + " years old.";  console.log(message);
**Engine name: null**
2024-03-11T15:03:07.663+05:30  WARN 27632 --- [pool-7-thread-1] io.camunda.zeebe.client.job.worker       : Worker scriptJobWorker failed to handle job with key 2251799816104816 of type script, sending fail command to broker
java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(String)" because "engine" is null
	at com.zeebe.camunda.ProductOrder.evaluateJavaScript( ~[classes/:na]
	at com.zeebe.camunda.ProductOrder.script( ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke( ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke( ~[na:na]
	at java.base/java.lang.reflect.Method.invoke( ~[na:na]
	at io.camunda.zeebe.spring.client.bean.MethodInfo.invoke( ~[spring-client-zeebe-8.3.1.jar:8.3.1]
	at io.camunda.zeebe.spring.client.jobhandling.JobHandlerInvokingSpringBeans.handle( ~[spring-client-zeebe-8.3.1.jar:8.3.1]
	at io.camunda.zeebe.client.impl.worker.JobRunnableFactoryImpl.executeJob( ~[zeebe-client-java-8.3.0.jar:8.3.0]
	at io.camunda.zeebe.client.impl.worker.JobRunnableFactoryImpl.lambda$create$0( ~[zeebe-client-java-8.3.0.jar:8.3.0]
	at java.base/java.util.concurrent.Executors$ ~[na:na]
	at java.base/ ~[na:na]
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker( ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$ ~[na:na]
	at java.base/ ~[na:na]

What is the issue here ?

Hi @Shivam_Agrawal - this isn’t an issue with Camunda, but rather with your Java code. The Javascript engine was removed in newer version of Java, I believe. I did a quick search on the error message you received and found this answer on StackOverflow that may help:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.