Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/java.base/share/classes/java/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ public Stream<E> parallelStream() {
* @since 21
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <T> SequencedCollection<T> unmodifiableSequencedCollection(SequencedCollection<? extends T> c) {
if (c.getClass() == UnmodifiableSequencedCollection.class) {
return (SequencedCollection<T>) c;
Expand Down Expand Up @@ -1366,6 +1367,7 @@ static class UnmodifiableSet<E> extends UnmodifiableCollection<E>
* @since 21
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <T> SequencedSet<T> unmodifiableSequencedSet(SequencedSet<? extends T> s) {
// Not checking for subclasses because of heap pollution and information leakage.
if (s.getClass() == UnmodifiableSequencedSet.class) {
Expand Down Expand Up @@ -1420,6 +1422,7 @@ public SequencedSet<E> reversed() {
* returned.
* @return an unmodifiable view of the specified sorted set.
*/
@SideEffectFree
public static <T> @PolyNonEmpty SortedSet<T> unmodifiableSortedSet(@PolyNonEmpty SortedSet<T> s) {
// Not checking for subclasses because of heap pollution and information leakage.
if (s.getClass() == UnmodifiableSortedSet.class) {
Expand Down Expand Up @@ -1482,6 +1485,7 @@ public SortedSet<E> tailSet(E fromElement) {
* @return an unmodifiable view of the specified navigable set
* @since 1.8
*/
@SideEffectFree
public static <T> @PolyNonEmpty NavigableSet<T> unmodifiableNavigableSet(@PolyNonEmpty NavigableSet<T> s) {
if (s.getClass() == UnmodifiableNavigableSet.class) {
return s;
Expand Down Expand Up @@ -1590,6 +1594,7 @@ public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {
* @return an unmodifiable view of the specified list.
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <T> @PolyGrowShrink @PolyNonEmpty List<T> unmodifiableList(@PolyGrowShrink @PolyNonEmpty List<? extends T> list) {
if (list.getClass() == UnmodifiableList.class || list.getClass() == UnmodifiableRandomAccessList.class) {
return (List<T>) list;
Expand Down Expand Up @@ -1779,6 +1784,7 @@ private Object writeReplace() {
* @return an unmodifiable view of the specified map.
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <K,V> @PolyNonEmpty Map<K,V> unmodifiableMap(@PolyNonEmpty Map<? extends K, ? extends V> m) {
// Not checking for subclasses because of heap pollution and information leakage.
if (m.getClass() == UnmodifiableMap.class) {
Expand Down Expand Up @@ -2185,6 +2191,7 @@ && eq(e.getKey(), t.getKey())
* @since 21
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <K,V> SequencedMap<K,V> unmodifiableSequencedMap(SequencedMap<? extends K, ? extends V> m) {
// Not checking for subclasses because of heap pollution and information leakage.
if (m.getClass() == UnmodifiableSequencedMap.class) {
Expand Down Expand Up @@ -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 <K,V> @PolyNonEmpty SortedMap<K,V> unmodifiableSortedMap(@PolyNonEmpty SortedMap<K, ? extends V> m) {
// Not checking for subclasses because of heap pollution and information leakage.
if (m.getClass() == UnmodifiableSortedMap.class) {
Expand Down Expand Up @@ -2316,6 +2324,7 @@ public SortedMap<K,V> tailMap(K fromKey)
* @since 1.8
*/
@SuppressWarnings("unchecked")
@SideEffectFree
public static <K,V> @PolyNonEmpty NavigableMap<K,V> unmodifiableNavigableMap(@PolyNonEmpty NavigableMap<K, ? extends V> m) {
if (m.getClass() == UnmodifiableNavigableMap.class) {
return (NavigableMap<K,V>) m;
Expand Down