diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 8dc86ceea7187..23951e4032641 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -1239,6 +1239,7 @@ public Stream parallelStream() { * @since 21 */ @SuppressWarnings("unchecked") + @SideEffectFree public static SequencedCollection unmodifiableSequencedCollection(SequencedCollection c) { if (c.getClass() == UnmodifiableSequencedCollection.class) { return (SequencedCollection) c; @@ -1366,6 +1367,7 @@ static class UnmodifiableSet extends UnmodifiableCollection * @since 21 */ @SuppressWarnings("unchecked") + @SideEffectFree public static SequencedSet unmodifiableSequencedSet(SequencedSet s) { // Not checking for subclasses because of heap pollution and information leakage. if (s.getClass() == UnmodifiableSequencedSet.class) { @@ -1420,6 +1422,7 @@ public SequencedSet reversed() { * returned. * @return an unmodifiable view of the specified sorted set. */ + @SideEffectFree public static @PolyNonEmpty SortedSet unmodifiableSortedSet(@PolyNonEmpty SortedSet s) { // Not checking for subclasses because of heap pollution and information leakage. if (s.getClass() == UnmodifiableSortedSet.class) { @@ -1482,6 +1485,7 @@ public SortedSet tailSet(E fromElement) { * @return an unmodifiable view of the specified navigable set * @since 1.8 */ + @SideEffectFree public static @PolyNonEmpty NavigableSet unmodifiableNavigableSet(@PolyNonEmpty NavigableSet s) { if (s.getClass() == UnmodifiableNavigableSet.class) { return s; @@ -1590,6 +1594,7 @@ public NavigableSet tailSet(E fromElement, boolean inclusive) { * @return an unmodifiable view of the specified list. */ @SuppressWarnings("unchecked") + @SideEffectFree public static @PolyGrowShrink @PolyNonEmpty List unmodifiableList(@PolyGrowShrink @PolyNonEmpty List list) { if (list.getClass() == UnmodifiableList.class || list.getClass() == UnmodifiableRandomAccessList.class) { return (List) list; @@ -1779,6 +1784,7 @@ private Object writeReplace() { * @return an unmodifiable view of the specified map. */ @SuppressWarnings("unchecked") + @SideEffectFree public static @PolyNonEmpty Map unmodifiableMap(@PolyNonEmpty Map m) { // Not checking for subclasses because of heap pollution and information leakage. if (m.getClass() == UnmodifiableMap.class) { @@ -2185,6 +2191,7 @@ && eq(e.getKey(), t.getKey()) * @since 21 */ @SuppressWarnings("unchecked") + @SideEffectFree public static SequencedMap unmodifiableSequencedMap(SequencedMap m) { // Not checking for subclasses because of heap pollution and information leakage. if (m.getClass() == UnmodifiableSequencedMap.class) { @@ -2260,6 +2267,7 @@ public V putLast(K k, V v) { * @return an unmodifiable view of the specified sorted map. */ @SuppressWarnings("unchecked") + @SideEffectFree public static @PolyNonEmpty SortedMap unmodifiableSortedMap(@PolyNonEmpty SortedMap m) { // Not checking for subclasses because of heap pollution and information leakage. if (m.getClass() == UnmodifiableSortedMap.class) { @@ -2316,6 +2324,7 @@ public SortedMap tailMap(K fromKey) * @since 1.8 */ @SuppressWarnings("unchecked") + @SideEffectFree public static @PolyNonEmpty NavigableMap unmodifiableNavigableMap(@PolyNonEmpty NavigableMap m) { if (m.getClass() == UnmodifiableNavigableMap.class) { return (NavigableMap) m;