Details
-
Sub-task
-
Resolution: Fixed
-
P2
-
8
-
b102
-
Verified
Description
The spec
http://download.java.net/jdk8/docs/api/java/util/Spliterator.html#SORTED
says:
"Characteristic value signifying that encounter order follows a defined sort order. If so, method getComparator() returns the associated Comparator, or null if all elements are Comparable and are sorted by their natural ordering."
This assertion is violated by TreeMap.entrySet().spliterator(). Please see the following code:
final Spliterator spliterator = new TreeMap() {{
put("a", "a");
put("b", "b");
}}.entrySet().spliterator();
System.out.println("spliterator.hasCharacteristics(Spliterator.SORTED) = " + spliterator.hasCharacteristics(Spliterator.SORTED));
System.out.println("spliterator.getComparator() = " + spliterator.getComparator());
spliterator.tryAdvance(e -> {Comparable c = (Comparable)e;});
The output will be:
spliterator.hasCharacteristics(Spliterator.SORTED) = true
spliterator.getComparator() = null
Exception in thread "main" java.lang.ClassCastException: java.util.TreeMap$Entry cannot be cast to java.lang.Comparable
at TreeMapEntrySet.lambda$0(TreeMapEntrySet.java:1)
at TreeMapEntrySet$$Lambda$1.accept(Unknown Source)
at java.util.TreeMap$EntrySpliterator.tryAdvance(TreeMap.java:2933)
at TreeMapEntrySet.main(TreeMapEntrySet.java:18)
The following JCK tests will fail due to this:
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/TreeMap/EntrySetSpliterator.html#EntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/TreeMap/EntrySetParallelStream.html#EntrySetParallelStream[checkSpliterator]
api/java_util/TreeMap/EntrySetStream.html#EntrySetStream[checkSpliterator]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetStream[checkSpliterator]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetParallelStream[checkSpliterator]
http://download.java.net/jdk8/docs/api/java/util/Spliterator.html#SORTED
says:
"Characteristic value signifying that encounter order follows a defined sort order. If so, method getComparator() returns the associated Comparator, or null if all elements are Comparable and are sorted by their natural ordering."
This assertion is violated by TreeMap.entrySet().spliterator(). Please see the following code:
final Spliterator spliterator = new TreeMap() {{
put("a", "a");
put("b", "b");
}}.entrySet().spliterator();
System.out.println("spliterator.hasCharacteristics(Spliterator.SORTED) = " + spliterator.hasCharacteristics(Spliterator.SORTED));
System.out.println("spliterator.getComparator() = " + spliterator.getComparator());
spliterator.tryAdvance(e -> {Comparable c = (Comparable)e;});
The output will be:
spliterator.hasCharacteristics(Spliterator.SORTED) = true
spliterator.getComparator() = null
Exception in thread "main" java.lang.ClassCastException: java.util.TreeMap$Entry cannot be cast to java.lang.Comparable
at TreeMapEntrySet.lambda$0(TreeMapEntrySet.java:1)
at TreeMapEntrySet$$Lambda$1.accept(Unknown Source)
at java.util.TreeMap$EntrySpliterator.tryAdvance(TreeMap.java:2933)
at TreeMapEntrySet.main(TreeMapEntrySet.java:18)
The following JCK tests will fail due to this:
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/TreeMap/EntrySetSpliterator.html#EntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/TreeMap/EntrySetParallelStream.html#EntrySetParallelStream[checkSpliterator]
api/java_util/TreeMap/EntrySetStream.html#EntrySetStream[checkSpliterator]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetSpliterator[getComparator_SORTED_naturally_comparingElements]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetStream[checkSpliterator]
api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapEntrySetParallelStream[checkSpliterator]