Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8235171

Adding lots of properties to objects causes properties to be readable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Tested with Java 11.02 using Windows 10/OSX-10.14/Debian 8.11

      A DESCRIPTION OF THE PROBLEM :
      See the example code. We have a large javascript array (about 4000 entries) and used the "reduce" function to create an object containing every array entry as a property.

      Calling this code several times causes the resulting object to have a varying number of properties, even though you'd expect it to always contain all elements of the array.

      We are suspecting the implementation in PropertyHashMap.java to have problems when the queue is taken into account.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the given code. Set a breakpoint at the System.out command and run the last engine.eval() command several within a debugging session:
      engine.eval("toMap(\"FactorName\")");

      Note: If the column "FactorName" references integers instead of strings, the method works as expected.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Every object created by the script should contain 4000 properties.
      ACTUAL -
      The number of properties varies between 399x to 4000.

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) throws ScriptException {
              final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
              final ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn");

              engine.eval("function createTestArray() {ar = [];for (var i = 0; i < 4000; i++) {ar[i] = {\"FactorName\": \"+i+\" + i, \"bla\": \"bla\" + i, \"one\": \"two\"};}return ar; } data = createTestArray();");
              engine.eval("function toMap(keyColumn) {var res = data.reduce(function(mapObject, row) {var key = row[keyColumn];if (mapObject[key]) {return mapObject;}mapObject[key] = row; return mapObject; }, {}); return res;}");
              final Object res = engine.eval("toMap(\"FactorName\")");
              System.out.println(res);
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the property "nashorn.propmap.queue.threshold" to something larger than the created array in javascript.

      FREQUENCY : often


        Attachments

          Activity

            People

            • Assignee:
              hannesw Hannes Wallnoefer
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: