Details
-
Bug
-
Resolution: Fixed
-
P2
-
8
-
b100
-
Verified
Description
The problem is reproducible with b95 and b95-lambda promotions.
Please see the following sample:
------------------------------------------------------------------------------------------------------
import java.util.*;
public class NowModifiable {
public static void main(String[] args) {
final HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("a", "a");
final Set<Map.Entry<String, String>> unmodifEntrySet = Collections.unmodifiableMap(hashMap).entrySet();
System.err.println("Entry type = " + unmodifEntrySet.iterator().next().getClass());
System.err.println("Entry type from stream = " + unmodifEntrySet.stream().findFirst().get().getClass());
unmodifEntrySet.stream().findFirst().get().setValue("new value1");
System.err.println("unexpectedly set a new value using element of a stream");
unmodifEntrySet.iterator().next().setValue("new value2");
System.err.println("unexpectedly set a new value using element of iterator");
}
}
------------------------------------------------------------------------------------------------------
The output will be like:
Entry type = class java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
Entry type from stream = class java.util.HashMap$Entry
unexpectedly set a new value using element of a stream
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry.setValue(Collections.java:1608)
The following JCK tests fail due to this issue:
api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetParallelStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetParallelStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetStream
Please see the following sample:
------------------------------------------------------------------------------------------------------
import java.util.*;
public class NowModifiable {
public static void main(String[] args) {
final HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("a", "a");
final Set<Map.Entry<String, String>> unmodifEntrySet = Collections.unmodifiableMap(hashMap).entrySet();
System.err.println("Entry type = " + unmodifEntrySet.iterator().next().getClass());
System.err.println("Entry type from stream = " + unmodifEntrySet.stream().findFirst().get().getClass());
unmodifEntrySet.stream().findFirst().get().setValue("new value1");
System.err.println("unexpectedly set a new value using element of a stream");
unmodifEntrySet.iterator().next().setValue("new value2");
System.err.println("unexpectedly set a new value using element of iterator");
}
}
------------------------------------------------------------------------------------------------------
The output will be like:
Entry type = class java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
Entry type from stream = class java.util.HashMap$Entry
unexpectedly set a new value using element of a stream
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry.setValue(Collections.java:1608)
The following JCK tests fail due to this issue:
api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetParallelStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetParallelStream
api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetStream
Attachments
Issue Links
- relates to
-
JDK-8020488 Stream created from Map.Entries of Cs.checkedMap(..) and Cs.unmodifiableMap(..) returns not the same elements as iterator over the same map entries
- Resolved