Skip to content

Commit 65aee08

Browse files
authored
feat(gax-java): add JSpecify Null annotations to gax (#13799)
### Summary This PR migrates the GAX (`sdk-platform-java/gax-java`) library to use JSpecify 1.0.0 nullability annotations (`@NullMarked` and `@Nullable`), replacing the previous `javax.annotation` references. ### Key Changes **JSpecify 1.0.0 Annotation Adoption in GAX:** - Applied `@NullMarked` at the class and package levels across GAX core classes to define non-null by default semantics. - Replaced imports of `javax.annotation.Nullable` with `org.jspecify.annotations.Nullable`. - Adopted type-use nullability declarations for generic parameters, arrays, and API settings (e.g. `java.time.@nullable Duration`, `List<@nullable T>`). ### Verification Results - https://docs.google.com/document/d/1nnlGdlKmvpDmH5U_wGEFpePGee9LYeRld7tI3g0L8qQ/edit?resourcekey=0-ebWO6NJdcB6Q7uYasPXcPw&tab=t.0
1 parent 43005fb commit 65aee08

426 files changed

Lines changed: 2277 additions & 1057 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sdk-platform-java/gax-java/gax-grpc/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ _COMPILE_DEPS = [
1616
"@com_google_guava_guava//jar",
1717
"@com_google_code_findbugs_jsr305//jar",
1818
"@com_google_code_gson_gson//jar",
19+
"@org_jspecify_jspecify//jar",
1920
"@org_threeten_threetenbp//jar",
2021
"@gapic_generator_java//google-auth-library-java/oauth2_http",
2122
"@gapic_generator_java//google-auth-library-java/credentials",

sdk-platform-java/gax-java/gax-grpc/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
</parent>
1616

1717
<dependencies>
18+
<dependency>
19+
<groupId>org.jspecify</groupId>
20+
<artifactId>jspecify</artifactId>
21+
</dependency>
1822
<dependency>
1923
<groupId>com.google.api</groupId>
2024
<artifactId>gax</artifactId>

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ApiStreamObserverDelegate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131

3232
import com.google.api.gax.rpc.ApiStreamObserver;
3333
import io.grpc.stub.StreamObserver;
34+
import org.jspecify.annotations.NullMarked;
3435

3536
/**
3637
* A delegate class that transfers calls to the ApiStreamObserver object.
3738
*
3839
* <p>Package-private for internal use.
3940
*/
41+
@NullMarked
4042
class ApiStreamObserverDelegate<V> implements StreamObserver<V> {
4143

4244
private final ApiStreamObserver<V> delegate;

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/CallOptionsUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
import io.grpc.Metadata.Key;
3838
import java.util.Collections;
3939
import java.util.Map;
40+
import org.jspecify.annotations.NullMarked;
4041

4142
/** A utility class that provides helper functions to work with custom call options. */
43+
@NullMarked
4244
class CallOptionsUtil {
4345
// this is a call option name, not a header name, it is not transferred over the wire
4446
private static final CallOptions.Key<Map<Key<String>, String>> DYNAMIC_HEADERS_CALL_OPTION_KEY =

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
import com.google.api.core.InternalApi;
3333
import io.grpc.ManagedChannel;
3434
import java.io.IOException;
35+
import org.jspecify.annotations.NullMarked;
3536

3637
/**
3738
* This interface represents a factory for creating one ManagedChannel
3839
*
3940
* <p>This is public only for technical reasons, for advanced usage.
4041
*/
42+
@NullMarked
4143
@InternalApi("For internal use by google-cloud-java clients only")
4244
public interface ChannelFactory {
4345
ManagedChannel createSingleChannel() throws IOException;

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
import java.util.concurrent.atomic.AtomicReference;
5757
import java.util.logging.Level;
5858
import java.util.logging.Logger;
59-
import javax.annotation.Nullable;
59+
import org.jspecify.annotations.NullMarked;
60+
import org.jspecify.annotations.Nullable;
6061

6162
/**
6263
* A {@link ManagedChannel} that will send requests round-robin via a set of channels.
@@ -68,6 +69,7 @@
6869
*
6970
* <p>Package-private for internal use.
7071
*/
72+
@NullMarked
7173
class ChannelPool extends ManagedChannel {
7274
static final String CHANNEL_POOL_CONSECUTIVE_RESIZING_WARNING =
7375
"The gRPC ChannelPool used in the client has been flagged to be repeatedly resizing (5+ times). See https://github.com/googleapis/google-cloud-java/blob/main/docs/grpc_channel_pool_guide.md for more information about this behavior.";
@@ -78,8 +80,8 @@ class ChannelPool extends ManagedChannel {
7880
private final ChannelFactory channelFactory;
7981
private final FixedExecutorProvider backgroundExecutorProvider;
8082

81-
private ScheduledFuture<?> refreshFuture = null;
82-
private ScheduledFuture<?> resizeFuture = null;
83+
private @Nullable ScheduledFuture<?> refreshFuture = null;
84+
private @Nullable ScheduledFuture<?> resizeFuture = null;
8385

8486
private final Object entryWriteLock = new Object();
8587
@VisibleForTesting final AtomicReference<ImmutableList<Entry>> entries = new AtomicReference<>();
@@ -621,7 +623,7 @@ public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
621623

622624
/** ClientCall wrapper that makes sure to decrement the outstanding RPC count on completion. */
623625
static class ReleasingClientCall<ReqT, RespT> extends SimpleForwardingClientCall<ReqT, RespT> {
624-
@Nullable private CancellationException cancellationException;
626+
private @Nullable CancellationException cancellationException;
625627
final Entry entry;
626628
private final AtomicBoolean wasClosed = new AtomicBoolean();
627629
private final AtomicBoolean wasReleased = new AtomicBoolean();

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPoolSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.auto.value.AutoValue;
3535
import com.google.common.base.Preconditions;
3636
import java.time.Duration;
37+
import org.jspecify.annotations.NullMarked;
3738

3839
/**
3940
* Settings to control {@link ChannelPool} behavior.
@@ -52,6 +53,7 @@
5253
*
5354
* <p>The settings in this class will be applied every minute.
5455
*/
56+
@NullMarked
5557
@BetaApi("surface for channel pool sizing is not yet stable")
5658
@AutoValue
5759
public abstract class ChannelPoolSettings {

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPrimer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131

3232
import com.google.api.core.InternalApi;
3333
import io.grpc.ManagedChannel;
34+
import org.jspecify.annotations.NullMarked;
3435

3536
/**
3637
* An interface to prepare a ManagedChannel for normal requests by priming the channel
3738
*
3839
* <p>This is public only for technical reasons, for advanced usage.
3940
*/
41+
@NullMarked
4042
@InternalApi("For internal use by google-cloud-java clients only")
4143
public interface ChannelPrimer {
4244
void primeChannel(ManagedChannel managedChannel);

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ExceptionResponseObserver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import com.google.api.gax.rpc.StateCheckingResponseObserver;
3434
import com.google.api.gax.rpc.StreamController;
3535
import java.util.concurrent.CancellationException;
36+
import org.jspecify.annotations.NullMarked;
3637

3738
/** Package-private for internal use. */
39+
@NullMarked
3840
class ExceptionResponseObserver<RequestT, ResponseT>
3941
extends StateCheckingResponseObserver<ResponseT> {
4042
private ResponseObserver<ResponseT> innerObserver;

sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GaxGrpcProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import com.google.api.gax.core.GaxProperties;
3434
import io.grpc.Channel;
3535
import java.util.regex.Pattern;
36+
import org.jspecify.annotations.NullMarked;
3637

3738
/** Provides properties of the GAX-GRPC library. */
39+
@NullMarked
3840
@InternalApi
3941
public class GaxGrpcProperties {
4042
private static final String GAX_GRPC_VERSION =

0 commit comments

Comments
 (0)