-
Task
-
Resolution: Fixed
-
L3 - Default
-
None
-
None
Using latest jdk 8u40 the spin test suite fails, with 8u25 everything works fine:
15:49:50 Failed tests: 15:49:50 JsonTreeEditListPropertyJavascriptTest.shouldFailInsertAtWithWrongObject Expected exception: org.camunda.spin.json.SpinJsonException 15:49:50 JsonTreeEditListPropertyJavascriptTest.shouldFailInsertWrongObjectAfterSearchObject Expected exception: org.camunda.spin.json.SpinJsonException 15:49:50 JsonTreeEditListPropertyJavascriptTest.shouldFailAppendWrongNode Expected exception: org.camunda.spin.json.SpinJsonException 15:49:50 JsonTreeEditListPropertyJavascriptTest.shouldFailInsertWrongObjectBeforeSearchObject Expected exception: org.camunda.spin.json.SpinJsonPropertyException
Reason:
Before java 8 u40, a script like
var node = S(input, "application/json"); var customers = node.prop("customers"); customers.insertAt(1, new Date());
resulted in calling the spin method #insertAt with an instance of NativeDate. This fails (as expected by the test), because insertAt only accepts primitives or lists or maps.
But now:
With jdk8u40 onwards, script objects are converted to ScriptObjectMirror whenever script objects are passed to Java layer - even with Object type params or assigned to a Object[] element.
Source: https://wiki.openjdk.java.net/display/Nashorn/Nashorn+jsr223+engine+notes
and the class ScriptObjectMirror implements Map (cf http://cr.openjdk.java.net/~sundar/jdk.nashorn.api/8u40/javadoc/jdk/nashorn/api/scripting/ScriptObjectMirror.html), which is why Spin happily inserts an (empty) map when calling #insertAt in the above script.
Solution possibilities:
- disable these tests for Javascript. Downside: this makes the API inconsistent. Users would not expect that a call such as in the above example suceeds and results in an empty map being inserted
- add specific handling/unwrapping of ScriptObjectMirror objects to the JacksonJsonDataFormat#createJsonNode. Downside: This couples the Jackson dataformat to a scripting engine which is in general not a good idea (although java script should always be available)
Some explanations on the change in Nashorn: