-
Type:
CSR
-
Resolution: Unresolved
-
Priority:
P4
-
Component/s: core-libs
-
None
-
behavioral
-
low
-
The new NPE only happens to an empty subSet, existing code would have ran into NPE for non-empty subSets before accidentally relying on this behavior.
-
Java API
-
Implementation
Summary
For the subSet from a java.util.TreeSet or a java.util.TreeMap::keySet, if such a set is empty, its spliterator now properly throws NullPointerException for tryAdvance and forEachRemaining.
Problem
The subSet for a TreeSet or a TreeMap.entrySet() got a customized spliterator implementation in JDK-8011426. That patch incorrectly omitted null checks when the subSet is empty, because the arguments are unused for empty subSets.
For example, in JShell:
new TreeSet<Integer>().subSet(-1, 1).spliterator().tryAdvance(null)
returns false instead of throwing a NullPointerException.
Solution
Throw a NullPointerException instead of returning false for tryAdvance or return successfully for forEachRemaining for the spliterator of such empty subsets.
Specification
No change. This is a behavioral change that aligns implementation to specification.
- csr of
-
JDK-8376698 Add Spliterator tests for TreeMap sub-maps
-
- Open
-