Differenence in behavior when creating/filling Arrays

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Tested on Windows and MacOS with Java Version 21.0.7 + Nashorn 15.7 (Maven). Worked with Java Version 11.0.27 (Nashorn included).

      A DESCRIPTION OF THE PROBLEM :
      When I create an empty array and push a java.lang.Long value, the value gets converted to a java.lang.Double.
      When I create an array with an initial java.lang.Long value, the value stays a java.lang.Long.

      This happens since we upgraded to Java 21 + Nashorn 15.7 (Maven Dependency).
      With Java 11 in both cases the values stayed java.lang.Long.

      I provide simple Javascript Code to demonstrate the behavior.

      var testArray1 = [];
      testArray1.push(new java.lang.Long(1234));
      // this results in a java.lang.Double Entry
      java.lang.System.out.println('1: ' + testArray1[0].getClass());

      var testArray2 = [new java.lang.Long(1234)];
      // this results in a java.lang.Long entry;
      java.lang.System.out.println('2: ' + testArray2[0].getClass());

      REGRESSION : Last worked in version 11.0.29

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute given Code with Nashorn Engine.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Both entries of both arrays should be of type java.lang.Long.
      ACTUAL -
      When creating empty array and push entry, type is of java.lang.Double.

      ---------- BEGIN SOURCE ----------
      var testArray1 = [];
      testArray1.push(new java.lang.Long(1234));
      // this results in a java.lang.Double Entry
      java.lang.System.out.println('1: ' + testArray1[0].getClass());

      var testArray2 = [new java.lang.Long(1234)];
      // this results in a java.lang.Long entry;
      java.lang.System.out.println('2: ' + testArray2[0].getClass());
      ---------- END SOURCE ----------

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: