Skip to content

Commit

Permalink
Address a couple nullness errors.
Browse files Browse the repository at this point in the history
One is from cl/725859649 (I _thought_ I had tested that change with nullness checking on), and the other is from [a change to the annotations for `Map.replace` used by Android](jspecify/jdk#118). (I think that the latter change should actually be leading to _more_ errors in our _other_ implementations of the 3-arg `Map.replace`, like in `Maps` and `Synchronized`. The lack of errors is probably a bug in the checker.)

RELNOTES=n/a
PiperOrigin-RevId: 728229469
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Feb 18, 2025
1 parent 46ce527 commit 7d7cc7d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public boolean remove(@Nullable Object key, @Nullable Object value) {

@CanIgnoreReturnValue
@Override
@SuppressWarnings("nullness") // https://github.com/jspecify/jdk/issues/118
public boolean replace(K key, V oldValue, V newValue) {
return delegate().replace(key, oldValue, newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public static <R, C, V> TreeBasedTable<R, C, V> create(
*/
public static <R, C, V> TreeBasedTable<R, C, V> create(TreeBasedTable<R, C, ? extends V> table) {
TreeBasedTable<R, C, V> result =
new TreeBasedTable<>(table.rowKeySet().comparator(), table.columnComparator());
// requireNonNull is safe, as discussed in rowComparator() below.
new TreeBasedTable<>(
requireNonNull(table.rowKeySet().comparator()), table.columnComparator());
result.putAll(table);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public boolean remove(@Nullable Object key, @Nullable Object value) {

@CanIgnoreReturnValue
@Override
@SuppressWarnings("nullness") // https://github.com/jspecify/jdk/issues/118
public boolean replace(K key, V oldValue, V newValue) {
return delegate().replace(key, oldValue, newValue);
}
Expand Down
4 changes: 3 additions & 1 deletion guava/src/com/google/common/collect/TreeBasedTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public static <R, C, V> TreeBasedTable<R, C, V> create(
*/
public static <R, C, V> TreeBasedTable<R, C, V> create(TreeBasedTable<R, C, ? extends V> table) {
TreeBasedTable<R, C, V> result =
new TreeBasedTable<>(table.rowKeySet().comparator(), table.columnComparator());
// requireNonNull is safe, as discussed in rowComparator() below.
new TreeBasedTable<>(
requireNonNull(table.rowKeySet().comparator()), table.columnComparator());
result.putAll(table);
return result;
}
Expand Down

0 comments on commit 7d7cc7d

Please sign in to comment.