Skip to content

Commit f0b8fc9

Browse files
committed
fix(auth): add missing @nullable annotations across credential types and providers
1 parent be8b8db commit f0b8fc9

37 files changed

Lines changed: 392 additions & 359 deletions

google-auth-library-java/appengine/java/com/google/auth/appengine/AppEngineCredentials.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public class AppEngineCredentials extends GoogleCredentials implements ServiceAc
6868

6969
private transient AppIdentityService appIdentityService;
7070

71-
private AppEngineCredentials(Collection<String> scopes, AppIdentityService appIdentityService) {
71+
private AppEngineCredentials(
72+
@Nullable Collection<String> scopes, @Nullable AppIdentityService appIdentityService) {
7273
this.scopes = scopes == null ? ImmutableSet.<String>of() : ImmutableList.copyOf(scopes);
7374
this.appIdentityService =
7475
appIdentityService != null
@@ -175,8 +176,8 @@ public Builder toBuilder() {
175176

176177
public static class Builder extends GoogleCredentials.Builder {
177178

178-
private Collection<String> scopes;
179-
private AppIdentityService appIdentityService;
179+
private @Nullable Collection<String> scopes;
180+
private @Nullable AppIdentityService appIdentityService;
180181

181182
protected Builder() {}
182183

@@ -186,22 +187,22 @@ protected Builder(AppEngineCredentials credentials) {
186187
}
187188

188189
@CanIgnoreReturnValue
189-
public Builder setScopes(Collection<String> scopes) {
190+
public Builder setScopes(@Nullable Collection<String> scopes) {
190191
this.scopes = scopes;
191192
return this;
192193
}
193194

194195
@CanIgnoreReturnValue
195-
public Builder setAppIdentityService(AppIdentityService appIdentityService) {
196+
public Builder setAppIdentityService(@Nullable AppIdentityService appIdentityService) {
196197
this.appIdentityService = appIdentityService;
197198
return this;
198199
}
199200

200-
public Collection<String> getScopes() {
201+
public @Nullable Collection<String> getScopes() {
201202
return scopes;
202203
}
203204

204-
public AppIdentityService getAppIdentityService() {
205+
public @Nullable AppIdentityService getAppIdentityService() {
205206
return appIdentityService;
206207
}
207208

google-auth-library-java/cab-token-generator/java/com/google/auth/credentialaccessboundary/ClientSideCredentialAccessBoundaryFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ public static Builder newBuilder() {
604604
*/
605605
public static class Builder {
606606
private GoogleCredentials sourceCredential;
607-
private HttpTransportFactory transportFactory;
608-
private String universeDomain;
607+
private @Nullable HttpTransportFactory transportFactory;
608+
private @Nullable String universeDomain;
609609
private String tokenExchangeEndpoint;
610610
private Duration minimumTokenLifetime;
611611
private Duration refreshMargin;
@@ -686,7 +686,7 @@ public Builder setRefreshMargin(Duration refreshMargin) {
686686
* @return this {@code Builder} object
687687
*/
688688
@CanIgnoreReturnValue
689-
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
689+
public Builder setHttpTransportFactory(@Nullable HttpTransportFactory transportFactory) {
690690
this.transportFactory = transportFactory;
691691
return this;
692692
}
@@ -698,7 +698,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
698698
* @return this {@code Builder} object
699699
*/
700700
@CanIgnoreReturnValue
701-
public Builder setUniverseDomain(String universeDomain) {
701+
public Builder setUniverseDomain(@Nullable String universeDomain) {
702702
this.universeDomain = universeDomain;
703703
return this;
704704
}
@@ -742,8 +742,8 @@ public ClientSideCredentialAccessBoundaryFactory build() {
742742
try {
743743
if (!universeDomain.equals(sourceCredential.getUniverseDomain())) {
744744
throw new IllegalArgumentException(
745-
"The client side access boundary credential's universe domain must be the same as the source "
746-
+ "credential.");
745+
"The client side access boundary credential's universe domain must be the same as the"
746+
+ " source credential.");
747747
}
748748
} catch (IOException e) {
749749
// Throwing an IOException would be a breaking change, so wrap it here.

google-auth-library-java/credentials/java/com/google/auth/Credentials.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public Map<String, List<String>> getRequestMetadata() throws IOException {
121121
* @param callback Callback to execute when the request is finished.
122122
*/
123123
public void getRequestMetadata(
124-
final URI uri, Executor executor, final RequestMetadataCallback callback) {
124+
final @Nullable URI uri, Executor executor, final RequestMetadataCallback callback) {
125125
executor.execute(
126126
new Runnable() {
127127
@Override
@@ -137,7 +137,7 @@ public void run() {
137137
* @param uri URI of the entry point for the request.
138138
* @param callback Callback handler to execute when the metadata completes.
139139
*/
140-
protected final void blockingGetToCallback(URI uri, RequestMetadataCallback callback) {
140+
protected final void blockingGetToCallback(@Nullable URI uri, RequestMetadataCallback callback) {
141141
Map<String, List<String>> result;
142142
try {
143143
result = getRequestMetadata(uri);

google-auth-library-java/oauth2_http/java/com/google/auth/mtls/MtlsUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.io.InputStream;
4141
import java.util.Locale;
4242
import org.jspecify.annotations.NullMarked;
43+
import org.jspecify.annotations.Nullable;
4344

4445
/**
4546
* Utility class for mTLS related operations.
@@ -65,14 +66,17 @@ private MtlsUtils() {
6566
* @throws IOException if the certificate configuration cannot be found or loaded.
6667
*/
6768
public static String getCertificatePath(
68-
EnvironmentProvider envProvider, PropertyProvider propProvider, String certConfigPathOverride)
69+
EnvironmentProvider envProvider,
70+
PropertyProvider propProvider,
71+
@Nullable String certConfigPathOverride)
6972
throws IOException {
7073
String certPath =
7174
getWorkloadCertificateConfiguration(envProvider, propProvider, certConfigPathOverride)
7275
.getCertPath();
7376
if (Strings.isNullOrEmpty(certPath)) {
7477
throw new CertificateSourceUnavailableException(
75-
"Certificate configuration loaded successfully, but does not contain a 'certificate_file' path.");
78+
"Certificate configuration loaded successfully, but does not contain a 'certificate_file'"
79+
+ " path.");
7680
}
7781
return certPath;
7882
}
@@ -92,7 +96,9 @@ public static String getCertificatePath(
9296
* @throws IOException if the configuration file cannot be found, read, or parsed
9397
*/
9498
static WorkloadCertificateConfiguration getWorkloadCertificateConfiguration(
95-
EnvironmentProvider envProvider, PropertyProvider propProvider, String certConfigPathOverride)
99+
EnvironmentProvider envProvider,
100+
PropertyProvider propProvider,
101+
@Nullable String certConfigPathOverride)
96102
throws IOException {
97103
File certConfig;
98104
if (certConfigPathOverride != null) {

google-auth-library-java/oauth2_http/java/com/google/auth/mtls/X509Provider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
public class X509Provider implements MtlsProvider {
5555
private final EnvironmentProvider envProvider;
5656
private final PropertyProvider propProvider;
57-
private final String certConfigPathOverride;
57+
private final @Nullable String certConfigPathOverride;
5858

5959
/**
6060
* Creates an X509 provider with an override path for the certificate configuration, bypassing the
@@ -69,7 +69,7 @@ public class X509Provider implements MtlsProvider {
6969
public X509Provider(
7070
EnvironmentProvider envProvider,
7171
PropertyProvider propProvider,
72-
String certConfigPathOverride) {
72+
@Nullable String certConfigPathOverride) {
7373
this.envProvider = envProvider;
7474
this.propProvider = propProvider;
7575
this.certConfigPathOverride = certConfigPathOverride;

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/AccessToken.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class AccessToken implements Serializable {
5656
* @param tokenValue String representation of the access token.
5757
* @param expirationTime Time when access token will expire.
5858
*/
59-
public AccessToken(String tokenValue, Date expirationTime) {
59+
public AccessToken(String tokenValue, @Nullable Date expirationTime) {
6060
this.tokenValue = tokenValue;
6161
this.expirationTimeMillis = (expirationTime == null) ? null : expirationTime.getTime();
6262
this.scopes = new ArrayList<>();
@@ -108,7 +108,7 @@ public String getTokenValue() {
108108
return new Date(expirationTimeMillis);
109109
}
110110

111-
Long getExpirationTimeMillis() {
111+
@Nullable Long getExpirationTimeMillis() {
112112
return expirationTimeMillis;
113113
}
114114

@@ -145,8 +145,8 @@ public boolean equals(@Nullable Object obj) {
145145
}
146146

147147
public static class Builder {
148-
private String tokenValue;
149-
private Date expirationTime;
148+
private @Nullable String tokenValue;
149+
private @Nullable Date expirationTime;
150150
private List<String> scopes = new ArrayList<>();
151151

152152
protected Builder() {}
@@ -157,15 +157,15 @@ protected Builder(AccessToken accessToken) {
157157
this.scopes = accessToken.getScopes();
158158
}
159159

160-
public String getTokenValue() {
160+
public @Nullable String getTokenValue() {
161161
return this.tokenValue;
162162
}
163163

164164
public List<String> getScopes() {
165165
return this.scopes;
166166
}
167167

168-
public Date getExpirationTime() {
168+
public @Nullable Date getExpirationTime() {
169169
return this.expirationTime;
170170
}
171171

@@ -176,15 +176,15 @@ public Builder setTokenValue(String tokenValue) {
176176
}
177177

178178
@CanIgnoreReturnValue
179-
public Builder setScopes(String scopes) {
179+
public Builder setScopes(@Nullable String scopes) {
180180
if (scopes != null && scopes.trim().length() > 0) {
181181
this.scopes = Arrays.asList(scopes.split(" "));
182182
}
183183
return this;
184184
}
185185

186186
@CanIgnoreReturnValue
187-
public Builder setScopes(List<String> scopes) {
187+
public Builder setScopes(@Nullable List<String> scopes) {
188188
if (scopes == null) {
189189
this.scopes = new ArrayList<>();
190190
} else {
@@ -195,7 +195,7 @@ public Builder setScopes(List<String> scopes) {
195195
}
196196

197197
@CanIgnoreReturnValue
198-
public Builder setExpirationTime(Date expirationTime) {
198+
public Builder setExpirationTime(@Nullable Date expirationTime) {
199199
this.expirationTime = expirationTime;
200200
return this;
201201
}

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/AppEngineCredentials.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ class AppEngineCredentials extends GoogleCredentials implements ServiceAccountSi
7474
private final Collection<String> scopes;
7575
private final boolean scopesRequired;
7676

77-
private transient Object appIdentityService;
78-
private transient Method getAccessToken;
79-
private transient Method getAccessTokenResult;
80-
private transient Method getExpirationTime;
81-
private transient Method signForApp;
82-
private transient Method getSignature;
83-
private transient String account;
84-
85-
AppEngineCredentials(Collection<String> scopes, Collection<String> defaultScopes)
77+
private transient @Nullable Object appIdentityService;
78+
private transient @Nullable Method getAccessToken;
79+
private transient @Nullable Method getAccessTokenResult;
80+
private transient @Nullable Method getExpirationTime;
81+
private transient @Nullable Method signForApp;
82+
private transient @Nullable Method getSignature;
83+
private transient @Nullable String account;
84+
85+
AppEngineCredentials(
86+
@Nullable Collection<String> scopes, @Nullable Collection<String> defaultScopes)
8687
throws IOException {
8788
// Use defaultScopes only when scopes don't exist.
8889
if (scopes == null || scopes.isEmpty()) {
@@ -96,7 +97,7 @@ class AppEngineCredentials extends GoogleCredentials implements ServiceAccountSi
9697
}
9798

9899
AppEngineCredentials(
99-
Collection<String> scopes,
100+
@Nullable Collection<String> scopes,
100101
@Nullable Collection<String> defaultScopes,
101102
AppEngineCredentials unscoped) {
102103
this.appIdentityService = unscoped.appIdentityService;
@@ -164,13 +165,13 @@ public boolean createScopedRequired() {
164165
}
165166

166167
@Override
167-
public GoogleCredentials createScoped(Collection<String> scopes) {
168+
public GoogleCredentials createScoped(@Nullable Collection<String> scopes) {
168169
return new AppEngineCredentials(scopes, null, this);
169170
}
170171

171172
@Override
172173
public GoogleCredentials createScoped(
173-
Collection<String> scopes, Collection<String> defaultScopes) {
174+
@Nullable Collection<String> scopes, @Nullable Collection<String> defaultScopes) {
174175
return new AppEngineCredentials(scopes, defaultScopes, this);
175176
}
176177

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/AwsCredentials.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public class AwsCredentials extends ExternalAccountCredentials {
8383
// Check that one and only one of supplier or credential source are provided.
8484
if (builder.awsSecurityCredentialsSupplier != null && builder.credentialSource != null) {
8585
throw new IllegalArgumentException(
86-
"AwsCredentials cannot have both an awsSecurityCredentialsSupplier and a credentialSource.");
86+
"AwsCredentials cannot have both an awsSecurityCredentialsSupplier and a"
87+
+ " credentialSource.");
8788
}
8889
if (builder.awsSecurityCredentialsSupplier == null && builder.credentialSource == null) {
8990
throw new IllegalArgumentException(
@@ -203,8 +204,7 @@ AwsSecurityCredentialsSupplier getAwsSecurityCredentialsSupplier() {
203204
return this.awsSecurityCredentialsSupplier;
204205
}
205206

206-
@Nullable
207-
public String getRegionalCredentialVerificationUrlOverride() {
207+
public @Nullable String getRegionalCredentialVerificationUrlOverride() {
208208
return this.regionalCredentialVerificationUrlOverride;
209209
}
210210

@@ -239,7 +239,7 @@ public static class Builder extends ExternalAccountCredentials.Builder {
239239

240240
private AwsSecurityCredentialsSupplier awsSecurityCredentialsSupplier;
241241

242-
private String regionalCredentialVerificationUrlOverride;
242+
private @Nullable String regionalCredentialVerificationUrlOverride;
243243

244244
Builder() {}
245245

@@ -277,13 +277,13 @@ public Builder setAwsSecurityCredentialsSupplier(
277277
*/
278278
@CanIgnoreReturnValue
279279
public Builder setRegionalCredentialVerificationUrlOverride(
280-
String regionalCredentialVerificationUrlOverride) {
280+
@Nullable String regionalCredentialVerificationUrlOverride) {
281281
this.regionalCredentialVerificationUrlOverride = regionalCredentialVerificationUrlOverride;
282282
return this;
283283
}
284284

285285
@CanIgnoreReturnValue
286-
public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) {
286+
public Builder setHttpTransportFactory(@Nullable HttpTransportFactory transportFactory) {
287287
super.setHttpTransportFactory(transportFactory);
288288
return this;
289289
}
@@ -319,55 +319,56 @@ public Builder setCredentialSource(AwsCredentialSource credentialSource) {
319319
}
320320

321321
@CanIgnoreReturnValue
322-
public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl) {
322+
public Builder setServiceAccountImpersonationUrl(
323+
@Nullable String serviceAccountImpersonationUrl) {
323324
super.setServiceAccountImpersonationUrl(serviceAccountImpersonationUrl);
324325
return this;
325326
}
326327

327328
@CanIgnoreReturnValue
328-
public Builder setTokenInfoUrl(String tokenInfoUrl) {
329+
public Builder setTokenInfoUrl(@Nullable String tokenInfoUrl) {
329330
super.setTokenInfoUrl(tokenInfoUrl);
330331
return this;
331332
}
332333

333334
@CanIgnoreReturnValue
334-
public Builder setQuotaProjectId(String quotaProjectId) {
335+
public Builder setQuotaProjectId(@Nullable String quotaProjectId) {
335336
super.setQuotaProjectId(quotaProjectId);
336337
return this;
337338
}
338339

339340
@CanIgnoreReturnValue
340-
public Builder setClientId(String clientId) {
341+
public Builder setClientId(@Nullable String clientId) {
341342
super.setClientId(clientId);
342343
return this;
343344
}
344345

345346
@CanIgnoreReturnValue
346-
public Builder setClientSecret(String clientSecret) {
347+
public Builder setClientSecret(@Nullable String clientSecret) {
347348
super.setClientSecret(clientSecret);
348349
return this;
349350
}
350351

351352
@CanIgnoreReturnValue
352-
public Builder setScopes(Collection<String> scopes) {
353+
public Builder setScopes(@Nullable Collection<String> scopes) {
353354
super.setScopes(scopes);
354355
return this;
355356
}
356357

357358
@CanIgnoreReturnValue
358-
public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) {
359+
public Builder setWorkforcePoolUserProject(@Nullable String workforcePoolUserProject) {
359360
super.setWorkforcePoolUserProject(workforcePoolUserProject);
360361
return this;
361362
}
362363

363364
@CanIgnoreReturnValue
364-
public Builder setServiceAccountImpersonationOptions(Map<String, Object> optionsMap) {
365+
public Builder setServiceAccountImpersonationOptions(@Nullable Map<String, Object> optionsMap) {
365366
super.setServiceAccountImpersonationOptions(optionsMap);
366367
return this;
367368
}
368369

369370
@CanIgnoreReturnValue
370-
public Builder setUniverseDomain(String universeDomain) {
371+
public Builder setUniverseDomain(@Nullable String universeDomain) {
371372
super.setUniverseDomain(universeDomain);
372373
return this;
373374
}

0 commit comments

Comments
 (0)