Skip to content

Commit

Permalink
Update code for forthcoming nullness annotations for JDK classes.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 559118450
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Aug 23, 2023
1 parent daacb1e commit a6940b6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.common.testing;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.GwtCompatible;
import java.io.ByteArrayInputStream;
Expand All @@ -42,7 +43,7 @@ static <T> T reserialize(T object) {
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
return (T) requireNonNull(in.readObject());
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void run() {
* @return true if the caller should continue, false if the associated FinalizableReferenceQueue
* is no longer referenced.
*/
private boolean cleanUp(Reference<?> reference) {
private boolean cleanUp(Reference<?> referenceParam) {
Reference<?> reference = referenceParam;
Method finalizeReferentMethod = getFinalizeReferentMethod();
if (finalizeReferentMethod == null) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion guava-testlib/src/com/google/common/testing/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.common.testing;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.GwtCompatible;
import java.io.ByteArrayInputStream;
Expand All @@ -42,7 +43,7 @@ static <T> T reserialize(T object) {
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
return (T) requireNonNull(in.readObject());
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/internal/Finalizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void run() {
* @return true if the caller should continue, false if the associated FinalizableReferenceQueue
* is no longer referenced.
*/
private boolean cleanUp(Reference<?> reference) {
private boolean cleanUp(Reference<?> referenceParam) {
Reference<?> reference = referenceParam;
Method finalizeReferentMethod = getFinalizeReferentMethod();
if (finalizeReferentMethod == null) {
return false;
Expand Down
10 changes: 7 additions & 3 deletions guava/src/com/google/common/util/concurrent/AtomicLongMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.J2ktIncompatible;
Expand Down Expand Up @@ -147,8 +148,11 @@ public long getAndAdd(K key, long delta) {
@CanIgnoreReturnValue
public long updateAndGet(K key, LongUnaryOperator updaterFunction) {
checkNotNull(updaterFunction);
return map.compute(
key, (k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue()));
Long result =
map.compute(
key,
(k, value) -> updaterFunction.applyAsLong((value == null) ? 0L : value.longValue()));
return requireNonNull(result);
}

/**
Expand Down Expand Up @@ -329,7 +333,7 @@ long putIfAbsent(K key, long newValue) {
return oldValue;
}
});
return noValue.get() ? 0L : result.longValue();
return noValue.get() ? 0L : requireNonNull(result).longValue();
}

/**
Expand Down

0 comments on commit a6940b6

Please sign in to comment.