Skip to content

Commit 50ebc70

Browse files
authored
cleanup(gax-java): remove javax.annotation.Nonnull usage (#13959)
This PR removes all occurrences of legacy javax.annotation.Nonnull annotations and imports across the gax-java codebase, removes the unused jsr305 dependency, and corrects misplaced/incorrect nullability annotations in the core modules (gax, gax-grpc, and gax-httpjson). ### Why this change is needed: As part of the repository-wide migration to JSpecify annotations, packages/classes are annotated with @NullMarked, making all unannotated types non-nullable by default. - The legacy javax.annotation.Nonnull annotations are redundant under JSpecify semantics and can be safely removed. - Resolving misplaced nullability signatures and aligning overridden methods enables compilation checks under NullAway static analysis with JSpecifyMode=true. ### JSR-305 (`jsr305`) Dependency Removal: We removed the `com.google.code.findbugs:jsr305` dependency from the `pom.xml` files. This is not a breaking change for the following reasons: * **Why it was removed**: Because we removed all references to the `javax.annotation` package in the codebase, the Maven dependency analyzer (`mvn dependency:analyze`) flagged `jsr305` as an **unused declared dependency**. Since our verification fails on any warning (`-DfailOnWarning=true`), the dependency had to be removed to pass presubmit checks. * **Why it's not a breaking change**: The dependency was declared with `provided` scope, meaning it was only used during compilation and was **never** distributed transitively to downstream users. Removing it has no runtime impact on library consumers. ### Changes: * Removed `import javax.annotation.Nonnull;` and `@Nonnull` from 30 files across `gax`, `gax-grpc`, and `gax-httpjson` (including test files). * Migrated remaining `javax.annotation.Nullable` usages in tests to JSpecify's `@Nullable` type-use annotation. * Removed the unused `jsr305` dependency from the `gax-java` module POMs. * Fixed type-use annotation placements and annotate missing annotations * Formatted all modified files using `fmt-maven-plugin`. * Verified that all compilation and dependency analysis stages pass cleanly.
1 parent 6487543 commit 50ebc70

48 files changed

Lines changed: 170 additions & 284 deletions

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/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@
8181
<artifactId>grpc-googleapis</artifactId>
8282
<scope>runtime</scope>
8383
</dependency>
84-
<dependency>
85-
<groupId>com.google.code.findbugs</groupId>
86-
<artifactId>jsr305</artifactId>
87-
<scope>provided</scope>
88-
</dependency>
84+
8985
<dependency>
9086
<groupId>org.graalvm.sdk</groupId>
9187
<artifactId>nativeimage</artifactId>

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import java.util.Map;
6565
import java.util.Objects;
6666
import java.util.Set;
67-
import javax.annotation.Nonnull;
6867
import org.jspecify.annotations.NullMarked;
6968
import org.jspecify.annotations.Nullable;
7069

@@ -413,7 +412,7 @@ public GrpcCallContext withExtraHeaders(Map<String, List<String>> extraHeaders)
413412
}
414413

415414
@Override
416-
public RetrySettings getRetrySettings() {
415+
public @Nullable RetrySettings getRetrySettings() {
417416
return retrySettings;
418417
}
419418

@@ -436,7 +435,7 @@ public GrpcCallContext withRetrySettings(RetrySettings retrySettings) {
436435
}
437436

438437
@Override
439-
public Set<StatusCode.Code> getRetryableCodes() {
438+
public @Nullable Set<StatusCode.Code> getRetryableCodes() {
440439
return retryableCodes;
441440
}
442441

@@ -665,7 +664,6 @@ public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams
665664

666665
/** {@inheritDoc} */
667666
@Override
668-
@Nonnull
669667
public ApiTracer getTracer() {
670668
ApiTracer tracer = callOptions.getOption(TRACER_KEY);
671669
if (tracer == null) {
@@ -676,7 +674,7 @@ public ApiTracer getTracer() {
676674

677675
/** {@inheritDoc} */
678676
@Override
679-
public GrpcCallContext withTracer(@Nonnull ApiTracer tracer) {
677+
public GrpcCallContext withTracer(ApiTracer tracer) {
680678
Preconditions.checkNotNull(tracer);
681679
return withCallOptions(callOptions.withOption(TRACER_KEY, tracer));
682680
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.google.longrunning.Operation;
6161
import com.google.longrunning.stub.OperationsStub;
6262
import io.grpc.MethodDescriptor;
63-
import javax.annotation.Nonnull;
6463
import org.jspecify.annotations.NullMarked;
6564

6665
/** Class with utility methods to create grpc-based direct callables. */
@@ -330,7 +329,7 @@ ClientStreamingCallable<RequestT, ResponseT> createClientStreamingCallable(
330329
}
331330

332331
@VisibleForTesting
333-
static ApiTracerContext getApiTracerContext(@Nonnull MethodDescriptor<?, ?> methodDescriptor) {
332+
static ApiTracerContext getApiTracerContext(MethodDescriptor<?, ?> methodDescriptor) {
334333
return ApiTracerContext.newBuilder()
335334
.setFullMethodName(methodDescriptor.getFullMethodName())
336335
.setTransport(ApiTracerContext.Transport.GRPC)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ public boolean needsExecutor() {
266266
return executor == null;
267267
}
268268

269-
@Nullable
270269
@Override
271-
public Executor getExecutor() {
270+
public @Nullable Executor getExecutor() {
272271
return executor;
273272
}
274273

@@ -541,9 +540,9 @@ boolean canUseDirectPathWithUniverseDomain() {
541540
return endpoint.contains(Credentials.GOOGLE_DEFAULT_UNIVERSE);
542541
}
543542

544-
@Nullable
545543
@VisibleForTesting
546-
ChannelCredentials createMtlsChannelCredentials() throws IOException, GeneralSecurityException {
544+
@Nullable ChannelCredentials createMtlsChannelCredentials()
545+
throws IOException, GeneralSecurityException {
547546
if (mtlsProvider == null) {
548547
return null;
549548
}
@@ -609,9 +608,8 @@ ChannelCredentials createMtlsChannelCredentials() throws IOException, GeneralSec
609608
* @return {@link ChannelCredentials} to use to create an mtls connection between client and S2A
610609
* @throws IOException on error
611610
*/
612-
@Nullable
613611
@VisibleForTesting
614-
ChannelCredentials createMtlsToS2AChannelCredentials(
612+
@Nullable ChannelCredentials createMtlsToS2AChannelCredentials(
615613
File trustBundle, File privateKey, File certChain) throws IOException {
616614
if (trustBundle == null || privateKey == null || certChain == null) {
617615
return null;

sdk-platform-java/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcDirectStreamControllerTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
import java.util.ArrayList;
5353
import java.util.List;
5454
import java.util.concurrent.TimeUnit;
55-
import javax.annotation.Nonnull;
56-
import javax.annotation.Nullable;
55+
import org.jspecify.annotations.Nullable;
5756
import org.junit.jupiter.api.Test;
5857
import org.junit.jupiter.api.Timeout;
5958

@@ -68,21 +67,19 @@ void testRetryNoRaceCondition() throws Exception {
6867
ManagedChannelBuilder.forAddress("localhost", 1234).usePlaintext().build();
6968
StreamResumptionStrategy<Color, Money> resumptionStrategy =
7069
new StreamResumptionStrategy<Color, Money>() {
71-
@Nonnull
70+
7271
@Override
7372
public StreamResumptionStrategy<Color, Money> createNew() {
7473
return this;
7574
}
7675

77-
@Nonnull
7876
@Override
7977
public Money processResponse(Money response) {
8078
return response;
8179
}
8280

83-
@Nullable
8481
@Override
85-
public Color getResumeRequest(Color originalRequest) {
82+
public @Nullable Color getResumeRequest(Color originalRequest) {
8683
return originalRequest;
8784
}
8885

sdk-platform-java/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
import java.util.logging.Level;
8282
import java.util.logging.LogRecord;
8383
import java.util.stream.Collectors;
84-
import javax.annotation.Nullable;
84+
import org.jspecify.annotations.Nullable;
8585
import org.junit.jupiter.api.AfterEach;
8686
import org.junit.jupiter.api.BeforeAll;
8787
import org.junit.jupiter.api.BeforeEach;
@@ -560,8 +560,7 @@ void testWithDefaultDirectPathServiceConfig() {
560560
assertThat(lbConfig.keySet()).containsExactly("pick_first");
561561
}
562562

563-
@Nullable
564-
private static Map<String, ?> getAsObject(Map<String, ?> json, String key) {
563+
private static @Nullable Map<String, ?> getAsObject(Map<String, ?> json, String key) {
565564
Object mapObject = json.get(key);
566565
if (mapObject == null) {
567566
return null;

sdk-platform-java/gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/MockClientCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import io.grpc.ClientCall;
3333
import io.grpc.Metadata;
3434
import io.grpc.Status;
35-
import javax.annotation.Nullable;
35+
import org.jspecify.annotations.Nullable;
3636

3737
public class MockClientCall<RequestT, ResponseT> extends ClientCall<RequestT, ResponseT> {
3838

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@
7272
<groupId>com.google.protobuf</groupId>
7373
<artifactId>protobuf-java-util</artifactId>
7474
</dependency>
75-
<dependency>
76-
<groupId>com.google.code.findbugs</groupId>
77-
<artifactId>jsr305</artifactId>
78-
<scope>provided</scope>
79-
</dependency>
75+
8076
<dependency>
8177
<groupId>com.google.auto.value</groupId>
8278
<artifactId>auto-value-annotations</artifactId>

sdk-platform-java/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallContext.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import java.util.Map;
5656
import java.util.Objects;
5757
import java.util.Set;
58-
import javax.annotation.Nonnull;
5958
import org.jspecify.annotations.NullMarked;
6059
import org.jspecify.annotations.Nullable;
6160

@@ -510,7 +509,7 @@ public HttpJsonCallOptions getCallOptions() {
510509
}
511510

512511
@Override
513-
public RetrySettings getRetrySettings() {
512+
public @Nullable RetrySettings getRetrySettings() {
514513
return retrySettings;
515514
}
516515

@@ -531,7 +530,7 @@ public HttpJsonCallContext withRetrySettings(RetrySettings retrySettings) {
531530
}
532531

533532
@Override
534-
public Set<StatusCode.Code> getRetryableCodes() {
533+
public @Nullable Set<StatusCode.Code> getRetryableCodes() {
535534
return retryableCodes;
536535
}
537536

@@ -588,7 +587,6 @@ public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) {
588587
return withCallOptions(builder.setDeadline(newDeadline).build());
589588
}
590589

591-
@Nonnull
592590
@Override
593591
public ApiTracer getTracer() {
594592
if (tracer == null) {
@@ -599,7 +597,7 @@ public ApiTracer getTracer() {
599597

600598
/** {@inheritDoc} */
601599
@Override
602-
public HttpJsonCallContext withTracer(@Nonnull ApiTracer newTracer) {
600+
public HttpJsonCallContext withTracer(ApiTracer newTracer) {
603601
Preconditions.checkNotNull(newTracer);
604602
HttpJsonCallOptions newCallOptions = callOptions.toBuilder().setTracer(newTracer).build();
605603

sdk-platform-java/gax-java/gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonCallableFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.google.api.gax.rpc.UnaryCallable;
4646
import com.google.api.gax.tracing.ApiTracerContext;
4747
import com.google.api.gax.tracing.TracedUnaryCallable;
48-
import javax.annotation.Nonnull;
4948
import org.jspecify.annotations.NullMarked;
5049

5150
/** Class with utility methods to create http/json-based direct callables. */
@@ -222,7 +221,7 @@ ServerStreamingCallable<RequestT, ResponseT> createServerStreamingCallable(
222221
return callable.withDefaultCallContext(clientContext.getDefaultCallContext());
223222
}
224223

225-
static ApiTracerContext getApiTracerContext(@Nonnull ApiMethodDescriptor<?, ?> methodDescriptor) {
224+
static ApiTracerContext getApiTracerContext(ApiMethodDescriptor<?, ?> methodDescriptor) {
226225
return ApiTracerContext.newBuilder()
227226
.setFullMethodName(methodDescriptor.getFullMethodName())
228227
.setHttpMethod(methodDescriptor.getHttpMethod())

0 commit comments

Comments
 (0)