Hi, I have a Javascript Literal expression in a DMN like this:
person.personContracts[0].processes.filter(f => f.processDefinitionKey == 'financialSituation')[0].state == 'COMPLETED'
The outcome is a boolean of course and language is set to Javascript. This is perfectly valid ECMAScript and works in browsers and other interpreters without problem. However, Camunda DMN gives following error when I use it:
ENGINE-REST-HTTP500 java.lang.AssertionError: Failed generating bytecode for <eval>:1
Does anyone have any ideas what it might be or how I can fix it?
Thanks,
Rogier
Hi @rogier.roukens,
the javascript expression is evaluated in the Java Virtual Machine. Depending on your Java and Camunda Version, it would be Nashorn or GraalVM.
I’m not a javascript expert, but there are differences between the implementations in the browser, Node.js and the Java engines.
Hope this helps, Ingo
Hi @Ingo_Richtsmeier,
Thanks for your reply. Interesting to know something about the underlying libraries. I don’t know which one we have.
The Javascript line is however not very modern and should work with most JS interpreters. So, my question still remains: why doesn’t it work and what can I do to make it work ?
Rogier
Hi,
I thought let’s look into these tools and found that Nashhorn is easily called from command line from JVM. So, I created a little js script to test my line and this is the result:
$ jjs jstest.js
Exception in thread "main" java.lang.AssertionError: Failed generating bytecode for jstest.js:72144
at jdk.nashorn.internal.codegen.CompilationPhase$BytecodeGenerationPhase.transform(CompilationPhase.java:431)
at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:624)
at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:655)
at jdk.nashorn.internal.runtime.Context.compile(Context.java:1317)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1251)
at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:627)
at jdk.nashorn.tools.Shell.runScripts(Shell.java:394)
at jdk.nashorn.tools.Shell.run(Shell.java:179)
...
So, looks indeed that at least Nashorn doesn’t understand this line of code. Very weird, but it is what it is… At least I can tweak the line until I can get it working.
Hi @rogier.roukens,
I’m not an expert in Javascript, so I could not answer your question. But I found that the Nashorn Engine was introduced with Java 8 in March 2014.
And in this article (https://www.baeldung.com/java-nashorn#language-extensions) they say that “Nashorn is targeting ECMAScript 5.1”.
Which ECMA Script level did you use in your example?
Cheers, Ingo
Hi @Ingo_Richtsmeier ,
Just I case anyone even runs into this and needs to know how I solved it.
I did some searching yesterday and found that the problem has more to do with the array type in Nashhorn not being a real Javascript array but more a Java array. Therefore, the filter() method (and other JS Array methods) do not exist. At least, that’s how I understand it now from threads like this one: https://stackoverflow.com/questions/44833161/iterating-over-array-with-nashorn
So, I solved it by just changing the expression language to groovy and changing my one-liner to:
person.personContracts[0].processes.findAll { it.processDefinitionKey == 'financialSituation' }[0].state == 'COMPLETED'
, which is syntatically identical to the JS line…
Thanks for the assistance!
Rogier