Skip to content

Commit

Permalink
Annotate some SequencedCollection-related APIs. (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Oct 7, 2024
1 parent 2b3db41 commit 12b9209
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ public Stream<E> parallelStream() {
* @since 21
*/
@SuppressWarnings("unchecked")
public static <T> SequencedCollection<T> unmodifiableSequencedCollection(SequencedCollection<? extends T> c) {
public static <T extends @Nullable Object> SequencedCollection<T> unmodifiableSequencedCollection(SequencedCollection<? extends T> c) {
if (c.getClass() == UnmodifiableSequencedCollection.class) {
return (SequencedCollection<T>) c;
}
Expand Down Expand Up @@ -1283,7 +1283,7 @@ static class UnmodifiableSet<E extends @Nullable Object> extends UnmodifiableCol
* @since 21
*/
@SuppressWarnings("unchecked")
public static <T> SequencedSet<T> unmodifiableSequencedSet(SequencedSet<? extends T> s) {
public static <T extends @Nullable Object> SequencedSet<T> unmodifiableSequencedSet(SequencedSet<? extends T> s) {
// Not checking for subclasses because of heap pollution and information leakage.
if (s.getClass() == UnmodifiableSequencedSet.class) {
return (SequencedSet<T>) s;
Expand Down Expand Up @@ -2004,7 +2004,7 @@ && eq(e.getKey(), t.getKey())
* @since 21
*/
@SuppressWarnings("unchecked")
public static <K,V> SequencedMap<K,V> unmodifiableSequencedMap(SequencedMap<? extends K, ? extends V> m) {
public static <K extends @Nullable Object,V extends @Nullable Object> 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) {
return (SequencedMap<K,V>) m;
Expand Down Expand Up @@ -6139,7 +6139,7 @@ private void readObjectNoData() throws java.io.ObjectStreamException {
* @throws IllegalArgumentException if {@code map} is not empty
* @since 21
*/
public static <E> SequencedSet<E> newSequencedSetFromMap(SequencedMap<E, Boolean> map) {
public static <E extends @Nullable Object> SequencedSet<E> newSequencedSetFromMap(SequencedMap<E, Boolean> map) {
if (! map.isEmpty()) // implicit null check
throw new IllegalArgumentException("Map is non-empty");
return new SequencedSetFromMap<>(map);
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/LinkedHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void afterNodeAccess(Node<K,V> e) {
*
* @since 21
*/
public V putFirst(K k, V v) {
public @Nullable V putFirst(K k, V v) {
try {
putMode = PUT_FIRST;
return this.put(k, v);
Expand All @@ -410,7 +410,7 @@ public V putFirst(K k, V v) {
*
* @since 21
*/
public V putLast(K k, V v) {
public @Nullable V putLast(K k, V v) {
try {
putMode = PUT_LAST;
return this.put(k, v);
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/SortedMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public interface SortedMap<K extends @Nullable Object,V extends @Nullable Object
* @throws UnsupportedOperationException always
* @since 21
*/
default V putFirst(K k, V v) {
default @Nullable V putFirst(K k, V v) {
throw new UnsupportedOperationException();
}

Expand All @@ -320,7 +320,7 @@ default V putFirst(K k, V v) {
* @throws UnsupportedOperationException always
* @since 21
*/
default V putLast(K k, V v) {
default @Nullable V putLast(K k, V v) {
throw new UnsupportedOperationException();
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/TreeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public K lastKey() {
* @throws UnsupportedOperationException always
* @since 21
*/
public V putFirst(K k, V v) {
public @Nullable V putFirst(K k, V v) {
throw new UnsupportedOperationException();
}

Expand All @@ -341,7 +341,7 @@ public V putFirst(K k, V v) {
* @throws UnsupportedOperationException always
* @since 21
*/
public V putLast(K k, V v) {
public @Nullable V putLast(K k, V v) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ public K lastKey() {
* @throws UnsupportedOperationException always
* @since 21
*/
public V putFirst(K k, V v) {
public @Nullable V putFirst(K k, V v) {
throw new UnsupportedOperationException();
}

Expand All @@ -1908,7 +1908,7 @@ public V putFirst(K k, V v) {
* @throws UnsupportedOperationException always
* @since 21
*/
public V putLast(K k, V v) {
public @Nullable V putLast(K k, V v) {
throw new UnsupportedOperationException();
}

Expand Down

0 comments on commit 12b9209

Please sign in to comment.