-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(gax-java): add JSpecify Null annotations to gax #13799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5a85552
9f25a79
f4e63af
471b684
1887dc5
7a0c69e
805997e
81b33cf
1ca35b7
ce4b81b
84806ee
178b92a
629620a
5b6153c
a11f36e
5214eb8
20bbada
8b73c7d
e333068
7c99224
91c37e8
fba10fa
d8ebf04
c094849
5e37306
bf8da72
5b0dbec
81ce6d1
619e82d
5f6018f
ea14da7
8f0db45
4c8ab1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,7 +65,8 @@ | |||||
| import java.util.Objects; | ||||||
| import java.util.Set; | ||||||
| import javax.annotation.Nonnull; | ||||||
| import javax.annotation.Nullable; | ||||||
| import org.jspecify.annotations.NullMarked; | ||||||
| import org.jspecify.annotations.Nullable; | ||||||
|
|
||||||
| /** | ||||||
| * GrpcCallContext encapsulates context data used to make a grpc call. | ||||||
|
|
@@ -75,6 +76,7 @@ | |||||
| * #withTransportChannel}, return copies of the object, but with one field changed. The immutability | ||||||
| * and thread safety of the arguments solely depends on the arguments themselves. | ||||||
| */ | ||||||
| @NullMarked | ||||||
| @BetaApi("Reference ApiCallContext instead - this class is likely to experience breaking changes") | ||||||
| public final class GrpcCallContext implements ApiCallContext { | ||||||
| private static final GrpcStatusCode UNAUTHENTICATED_STATUS_CODE = | ||||||
|
|
@@ -85,14 +87,14 @@ | |||||
| public static final CallOptions.Key<ApiTracer> TRACER_KEY = CallOptions.Key.create("gax.tracer"); | ||||||
|
|
||||||
| private final Channel channel; | ||||||
| @Nullable private final Credentials credentials; | ||||||
| private final @Nullable Credentials credentials; | ||||||
| private final CallOptions callOptions; | ||||||
| @Nullable private final java.time.Duration timeout; | ||||||
| @Nullable private final java.time.Duration streamWaitTimeout; | ||||||
| @Nullable private final java.time.Duration streamIdleTimeout; | ||||||
| @Nullable private final Integer channelAffinity; | ||||||
| @Nullable private final RetrySettings retrySettings; | ||||||
| @Nullable private final ImmutableSet<StatusCode.Code> retryableCodes; | ||||||
| private final java.time.@Nullable Duration timeout; | ||||||
| private final java.time.@Nullable Duration streamWaitTimeout; | ||||||
| private final java.time.@Nullable Duration streamIdleTimeout; | ||||||
| private final @Nullable Integer channelAffinity; | ||||||
| private final @Nullable RetrySettings retrySettings; | ||||||
| private final @Nullable ImmutableSet<StatusCode.Code> retryableCodes; | ||||||
| private final ImmutableMap<String, List<String>> extraHeaders; | ||||||
| private final ApiCallContextOptions options; | ||||||
| private final EndpointContext endpointContext; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under
Suggested change
|
||||||
|
|
@@ -135,12 +137,12 @@ | |||||
| } | ||||||
|
|
||||||
| private GrpcCallContext( | ||||||
| Channel channel, | ||||||
| @Nullable Channel channel, | ||||||
| @Nullable Credentials credentials, | ||||||
| CallOptions callOptions, | ||||||
| @Nullable java.time.Duration timeout, | ||||||
| @Nullable java.time.Duration streamWaitTimeout, | ||||||
| @Nullable java.time.Duration streamIdleTimeout, | ||||||
| java.time.@Nullable Duration timeout, | ||||||
| java.time.@Nullable Duration streamWaitTimeout, | ||||||
| java.time.@Nullable Duration streamIdleTimeout, | ||||||
| @Nullable Integer channelAffinity, | ||||||
| ImmutableMap<String, List<String>> extraHeaders, | ||||||
| ApiCallContextOptions options, | ||||||
|
|
@@ -257,12 +259,12 @@ | |||||
| /** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */ | ||||||
| @Override | ||||||
| @ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead") | ||||||
| public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) { | ||||||
| public GrpcCallContext withTimeout(org.threeten.bp.@Nullable Duration timeout) { | ||||||
| return withTimeoutDuration(toJavaTimeDuration(timeout)); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout) { | ||||||
| public GrpcCallContext withTimeoutDuration(java.time.@Nullable Duration timeout) { | ||||||
| // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. | ||||||
| if (timeout != null && (timeout.isZero() || timeout.isNegative())) { | ||||||
| timeout = null; | ||||||
|
|
@@ -289,17 +291,14 @@ | |||||
| isDirectPath); | ||||||
| } | ||||||
|
|
||||||
| /** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */ | ||||||
| @Nullable | ||||||
| @Override | ||||||
| @ObsoleteApi("Use getTimeoutDuration() instead") | ||||||
| public org.threeten.bp.Duration getTimeout() { | ||||||
| public org.threeten.bp.@Nullable Duration getTimeout() { | ||||||
| return toThreetenDuration(getTimeoutDuration()); | ||||||
| } | ||||||
|
|
||||||
| @Nullable | ||||||
| @Override | ||||||
| public java.time.Duration getTimeoutDuration() { | ||||||
| public java.time.@Nullable Duration getTimeoutDuration() { | ||||||
| return timeout; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -310,13 +309,13 @@ | |||||
| @Override | ||||||
| @ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead") | ||||||
| public GrpcCallContext withStreamWaitTimeout( | ||||||
| @Nullable org.threeten.bp.Duration streamWaitTimeout) { | ||||||
| org.threeten.bp.@Nullable Duration streamWaitTimeout) { | ||||||
| return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout)); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public GrpcCallContext withStreamWaitTimeoutDuration( | ||||||
| @Nullable java.time.Duration streamWaitTimeout) { | ||||||
| java.time.@Nullable Duration streamWaitTimeout) { | ||||||
| if (streamWaitTimeout != null) { | ||||||
| Preconditions.checkArgument( | ||||||
| streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); | ||||||
|
|
@@ -345,13 +344,13 @@ | |||||
| @Override | ||||||
| @ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead") | ||||||
| public GrpcCallContext withStreamIdleTimeout( | ||||||
| @Nullable org.threeten.bp.Duration streamIdleTimeout) { | ||||||
| org.threeten.bp.@Nullable Duration streamIdleTimeout) { | ||||||
| return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout)); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public GrpcCallContext withStreamIdleTimeoutDuration( | ||||||
| @Nullable java.time.Duration streamIdleTimeout) { | ||||||
| java.time.@Nullable Duration streamIdleTimeout) { | ||||||
| if (streamIdleTimeout != null) { | ||||||
| Preconditions.checkArgument( | ||||||
| streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); | ||||||
|
|
@@ -573,9 +572,8 @@ | |||||
|
|
||||||
| /** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */ | ||||||
| @Override | ||||||
| @Nullable | ||||||
| @ObsoleteApi("Use getStreamWaitTimeoutDuration() instead") | ||||||
| public org.threeten.bp.Duration getStreamWaitTimeout() { | ||||||
| public org.threeten.bp.@Nullable Duration getStreamWaitTimeout() { | ||||||
| return toThreetenDuration(getStreamWaitTimeoutDuration()); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -585,17 +583,15 @@ | |||||
| * @see ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration) | ||||||
| */ | ||||||
| @Override | ||||||
| @Nullable | ||||||
| public java.time.Duration getStreamWaitTimeoutDuration() { | ||||||
| public java.time.@Nullable Duration getStreamWaitTimeoutDuration() { | ||||||
| return streamWaitTimeout; | ||||||
| } | ||||||
|
|
||||||
| /** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */ | ||||||
| @Override | ||||||
| @Nullable | ||||||
| @ObsoleteApi("Use getStreamIdleTimeoutDuration() instead") | ||||||
| public org.threeten.bp.Duration getStreamIdleTimeout() { | ||||||
| public org.threeten.bp.@Nullable Duration getStreamIdleTimeout() { | ||||||
| return toThreetenDuration(getStreamIdleTimeoutDuration()); | ||||||
|
Check warning on line 594 in sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallContext.java
|
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -604,14 +600,12 @@ | |||||
| * @see ApiCallContext#withStreamIdleTimeoutDuration(java.time.Duration) | ||||||
| */ | ||||||
| @Override | ||||||
| @Nullable | ||||||
| public java.time.Duration getStreamIdleTimeoutDuration() { | ||||||
| public java.time.@Nullable Duration getStreamIdleTimeoutDuration() { | ||||||
| return streamIdleTimeout; | ||||||
| } | ||||||
|
|
||||||
| /** The channel affinity for this context. */ | ||||||
| @Nullable | ||||||
| public Integer getChannelAffinity() { | ||||||
| public @Nullable Integer getChannelAffinity() { | ||||||
| return channelAffinity; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -769,7 +763,7 @@ | |||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public boolean equals(Object o) { | ||||||
| public boolean equals(@Nullable Object o) { | ||||||
| if (this == o) { | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under
@NullMarked, fields that can be null must be explicitly annotated with@Nullable. Since the constructor parameterchannelis annotated with@NullableandGrpcCallContextcan be instantiated with a null channel (e.g., viacreateDefault()), thechannelfield should also be annotated with@Nullableto avoid static analysis warnings or potential null safety issues.