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

Nashorn: Java Sets and Queues must return undefined when using bracket notation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u31
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      Java Sets and Queues return null when attempting to access elements with the bracket notation (as can be done with Java lists). This should be changed so that such attempts return undefined instead, to be consistent with e.g.:

      var obj = {}
      obj[0]

      where obj[0] === undefined

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a script "nashorn.js" with the contents as below
      Run the script, on the command line: jjs nashorn.js

      === contents of nashorn.js ===

      var TreeSet = Java.type("java.util.TreeSet");
      var treeSet = new TreeSet();
      treeSet.add("a");
      print(treeSet[0]);

      var HashSet = Java.type("java.util.HashSet");
      var hashSet = new HashSet();
      hashSet.add("a");
      print(hashSet[0]);

      var PriorityQueue = Java.type("java.util.PriorityQueue");
      var priorityQueue = new PriorityQueue();
      priorityQueue.add("a");
      print(priorityQueue[0]);


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      3 lines are printed:

      undefined
      undefined
      undefined

      ACTUAL -
      3 lines are printed:

      null
      null
      null


      REPRODUCIBILITY :
      This bug can be reproduced always.

            attila Attila Szegedi
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: