-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u31
-
x86
-
windows_8
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.
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.
- duplicates
-
JDK-8057173 Treat POJOs as Object.seal()'d JS objects
-
- Closed
-