JDK-8079145 : jdk.nashorn.internal.runtime.arrays.IntArrayData.convert assertion
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-04-30
  • Updated: 2015-10-15
  • Resolved: 2015-05-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b66Fixed
Description
Nashorn can show an assertion failure when converting arrays of floats.
This worked in 1.8.0_31, fails in 1.8.0_40, 1.8.0_45.

function floatTest() {
    var jsArray = [35250.123456789];
    var jFloat = Java.to(jsArray, "float[]");
    print(j2jsarray(jFloat));
}

function j2jsarray(jArray) {
    var out = new Array();
    // out[0]=1.2; this will avoid the assertion failure.
    for (var i = 0; i < jArray.length; i++) {
        out[i] = jArray[i];
    }
    return out;
}

floatTest();


Exception in thread "main" java.lang.AssertionError
at
jdk.nashorn.internal.runtime.arrays.IntArrayData.convert(IntArrayData.java:191
)
at
jdk.nashorn.internal.runtime.arrays.IntArrayData.set(IntArrayData.java:241)
at
jdk.nashorn.internal.runtime.ScriptObject.doesNotHave(ScriptObject.java:3166)
at jdk.nashorn.internal.runtime.ScriptObject.set(ScriptObject.java:3384)
at
jdk.nashorn.internal.scripts.Script$Recompilation$2$167A$\^eval\_.j2jsarray(<e
val>:12)
at
jdk.nashorn.internal.scripts.Script$Recompilation$1$22$\^eval\_.floatTest(<eva
l>:5)
at jdk.nashorn.internal.scripts.Script$\^eval\_.:program(<eval>:17)
at
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java
:636)
at
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:229)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:387)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.jav
a:437)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.jav
a:401)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.jav
a:397)
at
jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:14
7)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
at FloatTestApp.main(FloatTestApp.java:13) 
Comments
Missed -ea option to trigger option (email communication). Reproduced the issue with -ea option. Fixing the issue.
20-05-2015

I checked that script with 8u60 early access build. java version "1.8.0_60-ea" Java(TM) SE Runtime Environment (build 1.8.0_60-ea-b11) Java HotSpot(TM) Server VM (build 25.60-b11, mixed mode) No exception was thrown and jjs prints 35250.125 I checked with jjs in latest jdk9-dev/nashorn build as well. Same result. I suppose the problem was only in 8u40 and 8u45. I suggest you please check it with jdk8u60 early access build downloadable @ https://jdk8.java.net/download.html
19-05-2015