JDK-8080501 : javaarrayconversion.js test is flawed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-05-15
  • Updated: 2016-01-14
  • Resolved: 2015-09-15
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
8u72Fixed 9 b83Fixed
Related Reports
Relates :  
Description
test/script/basic/javaarrayconversion.js asserts that an array of java objects can't be convert to a primitive Java array using the line:
 Java.to([new Java.type(sourceType)()], targetType + "[]"
expecting a TypeError. However the caught TypeError is actually "function type() { [native code] } is not a constructor function" because new is called on Java.type, not its result. So it should instead be:
 Java.to([new (Java.type(sourceType))()], targetType + "[]");
After this change the test fails with "no TypeError encountered" what suggests a bug in Nashorn.

Comments
I see. Thanks for the clarification, Attila.
19-05-2015

Yeah, the test needs to be fixed. The behavior, on the other hand, is correct ever since JDK-8072426. Basically, converting an arbitrary POJO to any of JS primitive types (numbers, booleans, strings) does work now; it has to, it basically forced us to come up with POJO semantics for ToPrimitive (and as consequence, [[DefaultValue]]) and that's what kicks in here. So, just as (new BitSet())|0 will evaluate to 0 and +(new BitSet()) will evaluate to NaN, converting a [new BitSet()] to int[] will produce [0] and converting it to double[] will produce [NaN].
18-05-2015