Skip to content

Commit

Permalink
Prepare code for more JDK nullness annotations.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 569590313
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Sep 29, 2023
1 parent b582866 commit 130709c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 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.checkArgument;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
Expand Down Expand Up @@ -410,7 +411,8 @@ private static <T> void setImplementation(Class<T> type, Class<? extends T> impl
}

private static <T> T createEmptyArray(Class<T> arrayType) {
return arrayType.cast(Array.newInstance(arrayType.getComponentType(), 0));
// getComponentType() is non-null because we call createEmptyArray only with an array type.
return arrayType.cast(Array.newInstance(requireNonNull(arrayType.getComponentType()), 0));
}

// Internal implementations of some classes, with public default constructor that get() needs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.AbstractOwnableSynchronizer;
import java.util.concurrent.locks.LockSupport;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;

@GwtCompatible(emulated = true)
Expand Down Expand Up @@ -234,6 +235,7 @@ private void setOwner(Thread thread) {
}

@VisibleForTesting
@CheckForNull
Thread getOwner() {
return super.getExclusiveOwnerThread();
}
Expand Down
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.checkArgument;
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
Expand Down Expand Up @@ -422,7 +423,8 @@ private static <T> void setImplementation(Class<T> type, Class<? extends T> impl
}

private static <T> T createEmptyArray(Class<T> arrayType) {
return arrayType.cast(Array.newInstance(arrayType.getComponentType(), 0));
// getComponentType() is non-null because we call createEmptyArray only with an array type.
return arrayType.cast(Array.newInstance(requireNonNull(arrayType.getComponentType()), 0));
}

// Internal implementations of some classes, with public default constructor that get() needs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.AbstractOwnableSynchronizer;
import java.util.concurrent.locks.LockSupport;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;

@GwtCompatible(emulated = true)
Expand Down Expand Up @@ -234,6 +235,7 @@ private void setOwner(Thread thread) {
}

@VisibleForTesting
@CheckForNull
Thread getOwner() {
return super.getExclusiveOwnerThread();
}
Expand Down

0 comments on commit 130709c

Please sign in to comment.