From 04dfd40c57b89c2d55327d5ea08036d749ebac02 Mon Sep 17 00:00:00 2001 From: Noam Lewis Date: Tue, 21 Nov 2023 15:33:31 +0200 Subject: [PATCH] fix: Remove -Xlint:unchecked, suppress all existing violations, add @CanIgnoreReturnValue (#1324) * chore: add @CanIgnoreReturnValue to builder set methods Preparation for enabling errorprone * fix: remove -Xlint:unchecked, suppress all existing violations --------- Co-authored-by: Noam Lewis --- .../auth/appengine/AppEngineCredentials.java | 3 +++ appengine/pom.xml | 5 +++++ .../com/google/auth/oauth2/AccessToken.java | 5 +++++ .../google/auth/oauth2/AwsRequestSignature.java | 10 ++++++++++ .../google/auth/oauth2/AwsRequestSigner.java | 3 +++ .../java/com/google/auth/oauth2/ClientId.java | 3 +++ .../auth/oauth2/CloudShellCredentials.java | 2 ++ .../auth/oauth2/ComputeEngineCredentials.java | 3 +++ .../auth/oauth2/CredentialAccessBoundary.java | 9 +++++++++ .../auth/oauth2/DownscopedCredentials.java | 4 ++++ ...xternalAccountAuthorizedUserCredentials.java | 11 +++++++++++ .../auth/oauth2/ExternalAccountCredentials.java | 17 +++++++++++++++++ .../com/google/auth/oauth2/GdchCredentials.java | 9 +++++++++ .../google/auth/oauth2/GoogleCredentials.java | 3 +++ .../google/auth/oauth2/IdTokenCredentials.java | 4 ++++ .../oauth2/IdentityPoolCredentialSource.java | 1 + .../auth/oauth2/IdentityPoolCredentials.java | 2 ++ .../auth/oauth2/ImpersonatedCredentials.java | 13 ++++++++++++- .../com/google/auth/oauth2/JwtCredentials.java | 6 ++++++ .../google/auth/oauth2/OAuth2Credentials.java | 4 ++++ .../oauth2/OAuth2CredentialsWithRefresh.java | 3 +++ .../com/google/auth/oauth2/OAuth2Utils.java | 1 + .../oauth2/PluggableAuthCredentialSource.java | 1 + .../auth/oauth2/PluggableAuthCredentials.java | 2 ++ .../auth/oauth2/ServiceAccountCredentials.java | 16 ++++++++++++++++ .../ServiceAccountJwtAccessCredentials.java | 7 +++++++ .../google/auth/oauth2/StsRequestHandler.java | 3 +++ .../auth/oauth2/StsTokenExchangeRequest.java | 7 +++++++ .../auth/oauth2/StsTokenExchangeResponse.java | 4 ++++ .../com/google/auth/oauth2/UserAuthorizer.java | 9 +++++++++ .../com/google/auth/oauth2/UserCredentials.java | 10 ++++++++++ .../google/auth/oauth2/AwsCredentialsTest.java | 2 ++ .../oauth2/ExternalAccountCredentialsTest.java | 2 ++ ...MockExternalAccountCredentialsTransport.java | 1 + oauth2_http/pom.xml | 5 +++++ pom.xml | 8 +++++++- 36 files changed, 196 insertions(+), 2 deletions(-) diff --git a/appengine/java/com/google/auth/appengine/AppEngineCredentials.java b/appengine/java/com/google/auth/appengine/AppEngineCredentials.java index 5b3024cf2..3af489d67 100644 --- a/appengine/java/com/google/auth/appengine/AppEngineCredentials.java +++ b/appengine/java/com/google/auth/appengine/AppEngineCredentials.java @@ -40,6 +40,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Collection; @@ -154,11 +155,13 @@ protected Builder(AppEngineCredentials credentials) { this.appIdentityService = credentials.appIdentityService; } + @CanIgnoreReturnValue public Builder setScopes(Collection scopes) { this.scopes = scopes; return this; } + @CanIgnoreReturnValue public Builder setAppIdentityService(AppIdentityService appIdentityService) { this.appIdentityService = appIdentityService; return this; diff --git a/appengine/pom.xml b/appengine/pom.xml index e93727943..b68b85431 100644 --- a/appengine/pom.xml +++ b/appengine/pom.xml @@ -79,5 +79,10 @@ test-jar testlib + + com.google.errorprone + error_prone_annotations + compile + diff --git a/oauth2_http/java/com/google/auth/oauth2/AccessToken.java b/oauth2_http/java/com/google/auth/oauth2/AccessToken.java index 5cb4a7803..40032ca47 100644 --- a/oauth2_http/java/com/google/auth/oauth2/AccessToken.java +++ b/oauth2_http/java/com/google/auth/oauth2/AccessToken.java @@ -32,6 +32,7 @@ package com.google.auth.oauth2; import com.google.common.base.MoreObjects; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -158,11 +159,13 @@ public Date getExpirationTime() { return this.expirationTime; } + @CanIgnoreReturnValue public Builder setTokenValue(String tokenValue) { this.tokenValue = tokenValue; return this; } + @CanIgnoreReturnValue public Builder setScopes(String scopes) { if (scopes != null && scopes.trim().length() > 0) { this.scopes = Arrays.asList(scopes.split(" ")); @@ -170,6 +173,7 @@ public Builder setScopes(String scopes) { return this; } + @CanIgnoreReturnValue public Builder setScopes(List scopes) { if (scopes == null) { this.scopes = new ArrayList<>(); @@ -180,6 +184,7 @@ public Builder setScopes(List scopes) { return this; } + @CanIgnoreReturnValue public Builder setExpirationTime(Date expirationTime) { this.expirationTime = expirationTime; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java b/oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java index 463b84676..99ec90cf4 100644 --- a/oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java +++ b/oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java @@ -31,6 +31,7 @@ package com.google.auth.oauth2; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.HashMap; import java.util.Map; @@ -130,46 +131,55 @@ static class Builder { private String region; private String authorizationHeader; + @CanIgnoreReturnValue Builder setSignature(String signature) { this.signature = signature; return this; } + @CanIgnoreReturnValue Builder setCredentialScope(String credentialScope) { this.credentialScope = credentialScope; return this; } + @CanIgnoreReturnValue Builder setSecurityCredentials(AwsSecurityCredentials awsSecurityCredentials) { this.awsSecurityCredentials = awsSecurityCredentials; return this; } + @CanIgnoreReturnValue Builder setUrl(String url) { this.url = url; return this; } + @CanIgnoreReturnValue Builder setHttpMethod(String httpMethod) { this.httpMethod = httpMethod; return this; } + @CanIgnoreReturnValue Builder setCanonicalHeaders(Map canonicalHeaders) { this.canonicalHeaders = new HashMap<>(canonicalHeaders); return this; } + @CanIgnoreReturnValue Builder setDate(String date) { this.date = date; return this; } + @CanIgnoreReturnValue Builder setRegion(String region) { this.region = region; return this; } + @CanIgnoreReturnValue Builder setAuthorizationHeader(String authorizationHeader) { this.authorizationHeader = authorizationHeader; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java b/oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java index 70d930bbe..a890c8814 100644 --- a/oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java +++ b/oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java @@ -38,6 +38,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.io.BaseEncoding; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.net.URI; import java.security.InvalidKeyException; import java.security.MessageDigest; @@ -298,11 +299,13 @@ private Builder( this.region = region; } + @CanIgnoreReturnValue Builder setRequestPayload(String requestPayload) { this.requestPayload = requestPayload; return this; } + @CanIgnoreReturnValue Builder setAdditionalHeaders(Map additionalHeaders) { if (additionalHeaders.containsKey("date") && additionalHeaders.containsKey("x-amz-date")) { throw new IllegalArgumentException("One of {date, x-amz-date} can be specified, not both."); diff --git a/oauth2_http/java/com/google/auth/oauth2/ClientId.java b/oauth2_http/java/com/google/auth/oauth2/ClientId.java index 80c3452f4..4f1de34c3 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ClientId.java +++ b/oauth2_http/java/com/google/auth/oauth2/ClientId.java @@ -34,6 +34,7 @@ import com.google.api.client.json.GenericJson; import com.google.api.client.json.JsonObjectParser; import com.google.api.client.util.Preconditions; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -184,11 +185,13 @@ protected Builder(ClientId clientId) { this.clientSecret = clientId.getClientSecret(); } + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; } + @CanIgnoreReturnValue public Builder setClientSecret(String clientSecret) { this.clientSecret = clientSecret; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java b/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java index 589539af6..8574f0108 100644 --- a/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/CloudShellCredentials.java @@ -34,6 +34,7 @@ import com.google.api.client.json.JsonParser; import com.google.common.base.Charsets; import com.google.common.base.MoreObjects; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -131,6 +132,7 @@ protected Builder(CloudShellCredentials credentials) { this.authPort = credentials.authPort; } + @CanIgnoreReturnValue public Builder setAuthPort(int authPort) { this.authPort = authPort; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java index 0370b6401..735860d86 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java @@ -47,6 +47,7 @@ import com.google.common.base.Joiner; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -549,11 +550,13 @@ protected Builder(ComputeEngineCredentials credentials) { this.scopes = credentials.scopes; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; } + @CanIgnoreReturnValue public Builder setScopes(Collection scopes) { this.scopes = scopes; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/CredentialAccessBoundary.java b/oauth2_http/java/com/google/auth/oauth2/CredentialAccessBoundary.java index be74d2747..39b528ab1 100644 --- a/oauth2_http/java/com/google/auth/oauth2/CredentialAccessBoundary.java +++ b/oauth2_http/java/com/google/auth/oauth2/CredentialAccessBoundary.java @@ -35,6 +35,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.client.json.GenericJson; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; @@ -124,11 +125,13 @@ private Builder() {} * @param rule the collection of rules to be set, should not be null * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setRules(List rule) { accessBoundaryRules = new ArrayList<>(checkNotNull(rule)); return this; } + @CanIgnoreReturnValue public CredentialAccessBoundary.Builder addRule(AccessBoundaryRule rule) { if (accessBoundaryRules == null) { accessBoundaryRules = new ArrayList<>(); @@ -218,6 +221,7 @@ private Builder() {} * @param availableResource the resource name to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAvailableResource(String availableResource) { this.availableResource = availableResource; return this; @@ -232,6 +236,7 @@ public Builder setAvailableResource(String availableResource) { * @param availablePermissions the collection of permissions to set, should not be null * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAvailablePermissions(List availablePermissions) { this.availablePermissions = new ArrayList<>(checkNotNull(availablePermissions)); return this; @@ -261,6 +266,7 @@ public Builder addAvailablePermission(String availablePermission) { * @param availabilityCondition the {@code AvailabilityCondition} to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAvailabilityCondition(AvailabilityCondition availabilityCondition) { this.availabilityCondition = availabilityCondition; return this; @@ -337,6 +343,7 @@ private Builder() {} * @param expression the expression to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setExpression(String expression) { this.expression = expression; return this; @@ -348,6 +355,7 @@ public Builder setExpression(String expression) { * @param title the title to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setTitle(String title) { this.title = title; return this; @@ -359,6 +367,7 @@ public Builder setTitle(String title) { * @param description the description to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setDescription(String description) { this.description = description; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java b/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java index f850f42c4..a8447a69a 100644 --- a/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/DownscopedCredentials.java @@ -36,6 +36,7 @@ import com.google.auth.http.HttpTransportFactory; import com.google.common.annotations.VisibleForTesting; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; /** @@ -166,16 +167,19 @@ public static class Builder extends OAuth2Credentials.Builder { private Builder() {} + @CanIgnoreReturnValue public Builder setSourceCredential(GoogleCredentials sourceCredential) { this.sourceCredential = sourceCredential; return this; } + @CanIgnoreReturnValue public Builder setCredentialAccessBoundary(CredentialAccessBoundary credentialAccessBoundary) { this.credentialAccessBoundary = credentialAccessBoundary; return this; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java index 3304eae75..0f87464bd 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountAuthorizedUserCredentials.java @@ -47,6 +47,7 @@ import com.google.auth.http.HttpTransportFactory; import com.google.common.base.MoreObjects; import com.google.common.io.BaseEncoding; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -401,6 +402,7 @@ protected Builder(ExternalAccountAuthorizedUserCredentials credentials) { * @param transportFactory the {@code HttpTransportFactory} to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; @@ -413,6 +415,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { * @param audience the audience to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAudience(String audience) { this.audience = audience; return this; @@ -424,6 +427,7 @@ public Builder setAudience(String audience) { * @param tokenUrl the token exchange url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setTokenUrl(String tokenUrl) { this.tokenUrl = tokenUrl; return this; @@ -435,6 +439,7 @@ public Builder setTokenUrl(String tokenUrl) { * @param tokenInfoUrl the token info url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setTokenInfoUrl(String tokenInfoUrl) { this.tokenInfoUrl = tokenInfoUrl; return this; @@ -446,6 +451,7 @@ public Builder setTokenInfoUrl(String tokenInfoUrl) { * @param revokeUrl the revoke url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setRevokeUrl(String revokeUrl) { this.revokeUrl = revokeUrl; return this; @@ -457,6 +463,7 @@ public Builder setRevokeUrl(String revokeUrl) { * @param refreshToken the refresh token * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setRefreshToken(String refreshToken) { this.refreshToken = refreshToken; return this; @@ -468,6 +475,7 @@ public Builder setRefreshToken(String refreshToken) { * @param clientId the client ID * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; @@ -479,6 +487,7 @@ public Builder setClientId(String clientId) { * @param clientSecret the client secret * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setClientSecret(String clientSecret) { this.clientSecret = clientSecret; return this; @@ -490,6 +499,7 @@ public Builder setClientSecret(String clientSecret) { * @param quotaProjectId the quota and billing project id to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); return this; @@ -501,6 +511,7 @@ public Builder setQuotaProjectId(String quotaProjectId) { * @param accessToken the access token * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAccessToken(AccessToken accessToken) { super.setAccessToken(accessToken); return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java index 85ac86b4b..45d7dda9c 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java @@ -39,6 +39,7 @@ import com.google.auth.RequestMetadataCallback; import com.google.auth.http.HttpTransportFactory; import com.google.common.base.MoreObjects; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; @@ -395,6 +396,7 @@ public static ExternalAccountCredentials fromStream( * @param transportFactory HTTP transport factory, creates the transport used to get access tokens * @return the credentials defined by the JSON */ + @SuppressWarnings("unchecked") static ExternalAccountCredentials fromJson( Map json, HttpTransportFactory transportFactory) { checkNotNull(json); @@ -762,6 +764,7 @@ protected Builder(ExternalAccountCredentials credentials) { * @param transportFactory the {@code HttpTransportFactory} to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; @@ -774,6 +777,7 @@ public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { * @param audience the Security Token Service audience to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setAudience(String audience) { this.audience = audience; return this; @@ -786,6 +790,7 @@ public Builder setAudience(String audience) { * @param subjectTokenType the Security Token Service subject token type to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setSubjectTokenType(String subjectTokenType) { this.subjectTokenType = subjectTokenType; return this; @@ -797,6 +802,7 @@ public Builder setSubjectTokenType(String subjectTokenType) { * @param tokenUrl the Security Token Service token exchange url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setTokenUrl(String tokenUrl) { this.tokenUrl = tokenUrl; return this; @@ -808,6 +814,7 @@ public Builder setTokenUrl(String tokenUrl) { * @param credentialSource the {@code CredentialSource} to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setCredentialSource(CredentialSource credentialSource) { this.credentialSource = credentialSource; return this; @@ -821,6 +828,7 @@ public Builder setCredentialSource(CredentialSource credentialSource) { * @param serviceAccountImpersonationUrl the service account impersonation url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonationUrl) { this.serviceAccountImpersonationUrl = serviceAccountImpersonationUrl; return this; @@ -833,6 +841,7 @@ public Builder setServiceAccountImpersonationUrl(String serviceAccountImpersonat * @param tokenInfoUrl the token info url to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setTokenInfoUrl(String tokenInfoUrl) { this.tokenInfoUrl = tokenInfoUrl; return this; @@ -844,6 +853,7 @@ public Builder setTokenInfoUrl(String tokenInfoUrl) { * @param quotaProjectId the quota and billing project id to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); return this; @@ -855,6 +865,7 @@ public Builder setQuotaProjectId(String quotaProjectId) { * @param clientId the service account client id to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; @@ -866,6 +877,7 @@ public Builder setClientId(String clientId) { * @param clientSecret the service account client secret to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setClientSecret(String clientSecret) { this.clientSecret = clientSecret; return this; @@ -877,6 +889,7 @@ public Builder setClientSecret(String clientSecret) { * @param scopes the request scopes to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setScopes(Collection scopes) { this.scopes = scopes; return this; @@ -890,6 +903,7 @@ public Builder setScopes(Collection scopes) { * @param workforcePoolUserProject the workforce pool user project number to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) { this.workforcePoolUserProject = workforcePoolUserProject; return this; @@ -901,6 +915,7 @@ public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) { * @param optionsMap the service account impersonation options to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setServiceAccountImpersonationOptions(Map optionsMap) { this.serviceAccountImpersonationOptions = new ServiceAccountImpersonationOptions(optionsMap); return this; @@ -912,6 +927,7 @@ public Builder setServiceAccountImpersonationOptions(Map options * @param universeDomain the universe domain to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue public Builder setUniverseDomain(String universeDomain) { this.universeDomain = universeDomain; return this; @@ -923,6 +939,7 @@ public Builder setUniverseDomain(String universeDomain) { * @param environmentProvider the {@code EnvironmentProvider} to set * @return this {@code Builder} object */ + @CanIgnoreReturnValue Builder setEnvironmentProvider(EnvironmentProvider environmentProvider) { this.environmentProvider = environmentProvider; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java index 4154361cd..4ffa87520 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GdchCredentials.java @@ -48,6 +48,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -394,41 +395,49 @@ protected Builder(GdchCredentials credentials) { this.lifetime = credentials.lifetime; } + @CanIgnoreReturnValue public Builder setProjectId(String projectId) { this.projectId = projectId; return this; } + @CanIgnoreReturnValue public Builder setPrivateKeyId(String privateKeyId) { this.privateKeyId = privateKeyId; return this; } + @CanIgnoreReturnValue public Builder setPrivateKey(PrivateKey privateKey) { this.privateKey = privateKey; return this; } + @CanIgnoreReturnValue public Builder setServiceIdentityName(String name) { this.serviceIdentityName = name; return this; } + @CanIgnoreReturnValue public Builder setTokenServerUri(URI tokenServerUri) { this.tokenServerUri = tokenServerUri; return this; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; } + @CanIgnoreReturnValue public Builder setCaCertPath(String caCertPath) { this.caCertPath = caCertPath; return this; } + @CanIgnoreReturnValue public Builder setGdchAudience(URI apiAudience) { this.apiAudience = apiAudience; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java index d12632a32..258a347c3 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java @@ -37,6 +37,7 @@ import com.google.api.client.util.Preconditions; import com.google.auth.http.HttpTransportFactory; import com.google.common.collect.ImmutableList; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -359,6 +360,7 @@ public GoogleCredentials build() { return new GoogleCredentials(this); } + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { this.quotaProjectId = quotaProjectId; return this; @@ -369,6 +371,7 @@ public String getQuotaProjectId() { } @Override + @CanIgnoreReturnValue public Builder setAccessToken(AccessToken token) { super.setAccessToken(token); return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java b/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java index be64a607b..a9bd03208 100644 --- a/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/IdTokenCredentials.java @@ -33,6 +33,7 @@ import com.google.api.client.util.Preconditions; import com.google.common.base.MoreObjects; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.util.List; import java.util.Objects; @@ -167,6 +168,7 @@ public static class Builder extends OAuth2Credentials.Builder { protected Builder() {} + @CanIgnoreReturnValue public Builder setIdTokenProvider(IdTokenProvider idTokenProvider) { this.idTokenProvider = idTokenProvider; return this; @@ -176,6 +178,7 @@ public IdTokenProvider getIdTokenProvider() { return this.idTokenProvider; } + @CanIgnoreReturnValue public Builder setTargetAudience(String targetAudience) { this.targetAudience = targetAudience; return this; @@ -185,6 +188,7 @@ public String getTargetAudience() { return this.targetAudience; } + @CanIgnoreReturnValue public Builder setOptions(List options) { this.options = options; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java index ea7166184..6fa9e6f41 100644 --- a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java +++ b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentialSource.java @@ -65,6 +65,7 @@ public class IdentityPoolCredentialSource extends ExternalAccountCredentials.Cre * *

Optional headers can be present, and should be keyed by `headers`. */ + @SuppressWarnings("unchecked") public IdentityPoolCredentialSource(Map credentialSourceMap) { super(credentialSourceMap); diff --git a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java index bb745ff55..fcfc7bb9b 100644 --- a/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/IdentityPoolCredentials.java @@ -40,6 +40,7 @@ import com.google.auth.oauth2.IdentityPoolCredentialSource.CredentialFormatType; import com.google.auth.oauth2.IdentityPoolCredentialSource.IdentityPoolCredentialSourceType; import com.google.common.io.CharStreams; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -182,6 +183,7 @@ public static class Builder extends ExternalAccountCredentials.Builder { super(credentials); } + @CanIgnoreReturnValue public Builder setWorkforcePoolUserProject(String workforcePoolUserProject) { super.setWorkforcePoolUserProject(workforcePoolUserProject); return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java index f9b90b01b..d54d5b547 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java @@ -49,6 +49,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.ObjectInputStream; import java.text.DateFormat; @@ -361,6 +362,7 @@ public byte[] sign(byte[] toSign) { * @return the credentials defined by the JSON * @throws IOException if the credential cannot be created from the JSON. */ + @SuppressWarnings("unchecked") static ImpersonatedCredentials fromJson( Map json, HttpTransportFactory transportFactory) throws IOException { @@ -418,7 +420,7 @@ public boolean createScopedRequired() { @Override public GoogleCredentials createScoped(Collection scopes) { return toBuilder() - .setScopes(new ArrayList(scopes)) + .setScopes(new ArrayList<>(scopes)) .setLifetime(this.lifetime) .setDelegates(this.delegates) .setHttpTransportFactory(this.transportFactory) @@ -624,6 +626,7 @@ protected Builder(GoogleCredentials sourceCredentials, String targetPrincipal) { this.targetPrincipal = targetPrincipal; } + @CanIgnoreReturnValue public Builder setSourceCredentials(GoogleCredentials sourceCredentials) { this.sourceCredentials = sourceCredentials; return this; @@ -633,6 +636,7 @@ public GoogleCredentials getSourceCredentials() { return this.sourceCredentials; } + @CanIgnoreReturnValue public Builder setTargetPrincipal(String targetPrincipal) { this.targetPrincipal = targetPrincipal; return this; @@ -642,6 +646,7 @@ public String getTargetPrincipal() { return this.targetPrincipal; } + @CanIgnoreReturnValue public Builder setDelegates(List delegates) { this.delegates = delegates; return this; @@ -651,6 +656,7 @@ public List getDelegates() { return this.delegates; } + @CanIgnoreReturnValue public Builder setScopes(List scopes) { this.scopes = scopes; return this; @@ -660,6 +666,7 @@ public List getScopes() { return this.scopes; } + @CanIgnoreReturnValue public Builder setLifetime(int lifetime) { this.lifetime = lifetime == 0 ? DEFAULT_LIFETIME_IN_SECONDS : lifetime; return this; @@ -669,6 +676,7 @@ public int getLifetime() { return this.lifetime; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; @@ -678,16 +686,19 @@ public HttpTransportFactory getHttpTransportFactory() { return transportFactory; } + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); return this; } + @CanIgnoreReturnValue public Builder setIamEndpointOverride(String iamEndpointOverride) { this.iamEndpointOverride = iamEndpointOverride; return this; } + @CanIgnoreReturnValue public Builder setCalendar(Calendar calendar) { this.calendar = calendar; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/JwtCredentials.java b/oauth2_http/java/com/google/auth/oauth2/JwtCredentials.java index 55fa3e5fb..3c21d31b9 100644 --- a/oauth2_http/java/com/google/auth/oauth2/JwtCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/JwtCredentials.java @@ -38,6 +38,7 @@ import com.google.auth.http.AuthHttpConstants; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.net.URI; import java.security.GeneralSecurityException; @@ -210,6 +211,7 @@ public static class Builder { protected Builder() {} + @CanIgnoreReturnValue public Builder setPrivateKey(PrivateKey privateKey) { this.privateKey = Preconditions.checkNotNull(privateKey); return this; @@ -219,6 +221,7 @@ public PrivateKey getPrivateKey() { return privateKey; } + @CanIgnoreReturnValue public Builder setPrivateKeyId(String privateKeyId) { this.privateKeyId = privateKeyId; return this; @@ -228,6 +231,7 @@ public String getPrivateKeyId() { return privateKeyId; } + @CanIgnoreReturnValue public Builder setJwtClaims(JwtClaims claims) { this.jwtClaims = Preconditions.checkNotNull(claims); return this; @@ -237,6 +241,7 @@ public JwtClaims getJwtClaims() { return jwtClaims; } + @CanIgnoreReturnValue public Builder setLifeSpanSeconds(Long lifeSpanSeconds) { this.lifeSpanSeconds = Preconditions.checkNotNull(lifeSpanSeconds); return this; @@ -246,6 +251,7 @@ public Long getLifeSpanSeconds() { return lifeSpanSeconds; } + @CanIgnoreReturnValue Builder setClock(Clock clock) { this.clock = Preconditions.checkNotNull(clock); return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java index 19196a7d0..7eafd530e 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java @@ -47,6 +47,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFutureTask; import com.google.common.util.concurrent.MoreExecutors; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; @@ -648,11 +649,13 @@ protected Builder(OAuth2Credentials credentials) { this.expirationMargin = credentials.expirationMargin; } + @CanIgnoreReturnValue public Builder setAccessToken(AccessToken token) { this.accessToken = token; return this; } + @CanIgnoreReturnValue public Builder setRefreshMargin(Duration refreshMargin) { this.refreshMargin = refreshMargin; return this; @@ -662,6 +665,7 @@ public Duration getRefreshMargin() { return refreshMargin; } + @CanIgnoreReturnValue public Builder setExpirationMargin(Duration expirationMargin) { this.expirationMargin = expirationMargin; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java index fea3dd38d..14e3ddae8 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2CredentialsWithRefresh.java @@ -33,6 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; /** @@ -99,12 +100,14 @@ private Builder() {} * {@link IllegalArgumentException} will be thrown. */ @Override + @CanIgnoreReturnValue public Builder setAccessToken(AccessToken token) { super.setAccessToken(token); return this; } /** Sets the {@link OAuth2RefreshHandler} to be used for token refreshes. */ + @CanIgnoreReturnValue public Builder setRefreshHandler(OAuth2RefreshHandler handler) { this.refreshHandler = handler; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java b/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java index fce0abc12..a1d276bad 100644 --- a/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java +++ b/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java @@ -170,6 +170,7 @@ static String validateOptionalString(Map map, String key, String } /** Return the specified list of strings from JSON or throw a helpful error message. */ + @SuppressWarnings("unchecked") static List validateOptionalListString( Map map, String key, String errorPrefix) throws IOException { Object value = map.get(key); diff --git a/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentialSource.java b/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentialSource.java index 1554dd9cb..44406e7f9 100644 --- a/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentialSource.java +++ b/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentialSource.java @@ -80,6 +80,7 @@ public class PluggableAuthCredentialSource extends ExternalAccountCredentials.Cr // location. @Nullable final String outputFilePath; + @SuppressWarnings("unchecked") public PluggableAuthCredentialSource(Map credentialSourceMap) { super(credentialSourceMap); diff --git a/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentials.java b/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentials.java index 84eb6dc55..5caa567c1 100644 --- a/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/PluggableAuthCredentials.java @@ -33,6 +33,7 @@ import com.google.auth.oauth2.ExecutableHandler.ExecutableOptions; import com.google.common.annotations.VisibleForTesting; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -219,6 +220,7 @@ public static class Builder extends ExternalAccountCredentials.Builder { this.handler = credentials.handler; } + @CanIgnoreReturnValue public Builder setExecutableHandler(ExecutableHandler handler) { this.handler = handler; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java index c6c95a71c..c83c8ff97 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -56,6 +56,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -1005,78 +1006,93 @@ protected Builder(ServiceAccountCredentials credentials) { this.defaultRetriesEnabled = credentials.defaultRetriesEnabled; } + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; } + @CanIgnoreReturnValue public Builder setClientEmail(String clientEmail) { this.clientEmail = clientEmail; return this; } + @CanIgnoreReturnValue public Builder setPrivateKey(PrivateKey privateKey) { this.privateKey = privateKey; return this; } + @CanIgnoreReturnValue public Builder setPrivateKeyString(String privateKeyPkcs8) throws IOException { this.privateKey = OAuth2Utils.privateKeyFromPkcs8(privateKeyPkcs8); return this; } + @CanIgnoreReturnValue public Builder setPrivateKeyId(String privateKeyId) { this.privateKeyId = privateKeyId; return this; } + @CanIgnoreReturnValue public Builder setScopes(Collection scopes) { this.scopes = scopes; this.defaultScopes = ImmutableSet.of(); return this; } + @CanIgnoreReturnValue public Builder setScopes(Collection scopes, Collection defaultScopes) { this.scopes = scopes; this.defaultScopes = defaultScopes; return this; } + @CanIgnoreReturnValue public Builder setServiceAccountUser(String serviceAccountUser) { this.serviceAccountUser = serviceAccountUser; return this; } + @CanIgnoreReturnValue public Builder setProjectId(String projectId) { this.projectId = projectId; return this; } + @CanIgnoreReturnValue public Builder setTokenServerUri(URI tokenServerUri) { this.tokenServerUri = tokenServerUri; return this; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; } + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); return this; } + @CanIgnoreReturnValue public Builder setLifetime(int lifetime) { this.lifetime = lifetime == 0 ? DEFAULT_LIFETIME_IN_SECONDS : lifetime; return this; } + @CanIgnoreReturnValue public Builder setUseJwtAccessWithScope(boolean useJwtAccessWithScope) { this.useJwtAccessWithScope = useJwtAccessWithScope; return this; } + @CanIgnoreReturnValue public Builder setDefaultRetriesEnabled(boolean defaultRetriesEnabled) { this.defaultRetriesEnabled = defaultRetriesEnabled; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountJwtAccessCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountJwtAccessCredentials.java index a318ef72f..6fc338405 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountJwtAccessCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountJwtAccessCredentials.java @@ -50,6 +50,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -485,31 +486,37 @@ protected Builder(ServiceAccountJwtAccessCredentials credentials) { this.quotaProjectId = credentials.quotaProjectId; } + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; } + @CanIgnoreReturnValue public Builder setClientEmail(String clientEmail) { this.clientEmail = clientEmail; return this; } + @CanIgnoreReturnValue public Builder setPrivateKey(PrivateKey privateKey) { this.privateKey = privateKey; return this; } + @CanIgnoreReturnValue public Builder setPrivateKeyId(String privateKeyId) { this.privateKeyId = privateKeyId; return this; } + @CanIgnoreReturnValue public Builder setDefaultAudience(URI defaultAudience) { this.defaultAudience = defaultAudience; return this; } + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { this.quotaProjectId = quotaProjectId; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/StsRequestHandler.java b/oauth2_http/java/com/google/auth/oauth2/StsRequestHandler.java index 3f93ad86e..ba7d27b81 100644 --- a/oauth2_http/java/com/google/auth/oauth2/StsRequestHandler.java +++ b/oauth2_http/java/com/google/auth/oauth2/StsRequestHandler.java @@ -43,6 +43,7 @@ import com.google.api.client.json.JsonParser; import com.google.api.client.util.GenericData; import com.google.common.base.Joiner; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -199,11 +200,13 @@ private Builder( this.httpRequestFactory = httpRequestFactory; } + @CanIgnoreReturnValue public StsRequestHandler.Builder setHeaders(HttpHeaders headers) { this.headers = headers; return this; } + @CanIgnoreReturnValue public StsRequestHandler.Builder setInternalOptions(String internalOptions) { this.internalOptions = internalOptions; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeRequest.java b/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeRequest.java index b5d0055ab..a231fe383 100644 --- a/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeRequest.java +++ b/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeRequest.java @@ -33,6 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.List; import javax.annotation.Nullable; @@ -154,31 +155,37 @@ private Builder(String subjectToken, String subjectTokenType) { this.subjectTokenType = subjectTokenType; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setResource(String resource) { this.resource = resource; return this; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setAudience(String audience) { this.audience = audience; return this; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setRequestTokenType(String requestedTokenType) { this.requestedTokenType = requestedTokenType; return this; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setScopes(List scopes) { this.scopes = scopes; return this; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setActingParty(ActingParty actingParty) { this.actingParty = actingParty; return this; } + @CanIgnoreReturnValue public StsTokenExchangeRequest.Builder setInternalOptions(String internalOptions) { this.internalOptions = internalOptions; return this; diff --git a/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeResponse.java b/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeResponse.java index ef0382689..90a94e16d 100644 --- a/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeResponse.java +++ b/oauth2_http/java/com/google/auth/oauth2/StsTokenExchangeResponse.java @@ -33,6 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -121,16 +122,19 @@ private Builder(String accessToken, String issuedTokenType, String tokenType) { this.tokenType = tokenType; } + @CanIgnoreReturnValue public StsTokenExchangeResponse.Builder setExpiresInSeconds(long expiresInSeconds) { this.expiresInSeconds = expiresInSeconds; return this; } + @CanIgnoreReturnValue public StsTokenExchangeResponse.Builder setRefreshToken(String refreshToken) { this.refreshToken = refreshToken; return this; } + @CanIgnoreReturnValue public StsTokenExchangeResponse.Builder setScopes(List scopes) { if (scopes != null) { this.scopes = new ArrayList<>(scopes); diff --git a/oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java b/oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java index 63cc23170..19305180e 100644 --- a/oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java +++ b/oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java @@ -43,6 +43,7 @@ import com.google.api.client.util.Preconditions; import com.google.auth.http.HttpTransportFactory; import com.google.common.collect.ImmutableList; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.IOException; import java.net.URI; import java.net.URL; @@ -501,41 +502,49 @@ protected Builder(UserAuthorizer authorizer) { this.pkce = new DefaultPKCEProvider(); } + @CanIgnoreReturnValue public Builder setClientId(ClientId clientId) { this.clientId = clientId; return this; } + @CanIgnoreReturnValue public Builder setTokenStore(TokenStore tokenStore) { this.tokenStore = tokenStore; return this; } + @CanIgnoreReturnValue public Builder setScopes(Collection scopes) { this.scopes = scopes; return this; } + @CanIgnoreReturnValue public Builder setTokenServerUri(URI tokenServerUri) { this.tokenServerUri = tokenServerUri; return this; } + @CanIgnoreReturnValue public Builder setCallbackUri(URI callbackUri) { this.callbackUri = callbackUri; return this; } + @CanIgnoreReturnValue public Builder setUserAuthUri(URI userAuthUri) { this.userAuthUri = userAuthUri; return this; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; } + @CanIgnoreReturnValue public Builder setPKCEProvider(PKCEProvider pkce) { if (pkce != null) { if (pkce.getCodeChallenge() == null diff --git a/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java b/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java index 0f92290c0..abc040f25 100644 --- a/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/UserCredentials.java @@ -47,6 +47,7 @@ import com.google.api.client.util.Preconditions; import com.google.auth.http.HttpTransportFactory; import com.google.common.base.MoreObjects; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -388,46 +389,55 @@ protected Builder(UserCredentials credentials) { this.tokenServerUri = credentials.tokenServerUri; } + @CanIgnoreReturnValue public Builder setClientId(String clientId) { this.clientId = clientId; return this; } + @CanIgnoreReturnValue public Builder setClientSecret(String clientSecret) { this.clientSecret = clientSecret; return this; } + @CanIgnoreReturnValue public Builder setRefreshToken(String refreshToken) { this.refreshToken = refreshToken; return this; } + @CanIgnoreReturnValue public Builder setTokenServerUri(URI tokenServerUri) { this.tokenServerUri = tokenServerUri; return this; } + @CanIgnoreReturnValue public Builder setHttpTransportFactory(HttpTransportFactory transportFactory) { this.transportFactory = transportFactory; return this; } + @CanIgnoreReturnValue public Builder setAccessToken(AccessToken token) { super.setAccessToken(token); return this; } + @CanIgnoreReturnValue public Builder setExpirationMargin(Duration expirationMargin) { super.setExpirationMargin(expirationMargin); return this; } + @CanIgnoreReturnValue public Builder setRefreshMargin(Duration refreshMargin) { super.setRefreshMargin(refreshMargin); return this; } + @CanIgnoreReturnValue public Builder setQuotaProjectId(String quotaProjectId) { super.setQuotaProjectId(quotaProjectId); return this; diff --git a/oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java index b1e384020..b6e73fcce 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java @@ -210,6 +210,7 @@ public void refreshAccessToken_withServiceAccountImpersonationOptions() throws I } @Test + @SuppressWarnings("unchecked") public void retrieveSubjectToken() throws IOException { MockExternalAccountCredentialsTransportFactory transportFactory = new MockExternalAccountCredentialsTransportFactory(); @@ -254,6 +255,7 @@ public void retrieveSubjectToken() throws IOException { } @Test + @SuppressWarnings("unchecked") public void retrieveSubjectTokenWithSessionTokenUrl() throws IOException { MockExternalAccountCredentialsTransportFactory transportFactory = new MockExternalAccountCredentialsTransportFactory(); diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java index ec558cfa8..6d2fe38dc 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ExternalAccountCredentialsTest.java @@ -346,6 +346,7 @@ public void fromJson_pluggableAuthCredentialsWorkforce() { } @Test + @SuppressWarnings("unchecked") public void fromJson_pluggableAuthCredentials_allExecutableOptionsSet() { GenericJson json = buildJsonPluggableAuthCredential(); Map credentialSourceMap = (Map) json.get("credential_source"); @@ -400,6 +401,7 @@ public void fromJson_pluggableAuthCredentialsWithServiceAccountImpersonationOpti } @Test + @SuppressWarnings("unchecked") public void fromJson_pluggableAuthCredentials_withUniverseDomain() { GenericJson json = buildJsonPluggableAuthCredential(); json.set("universe_domain", "universeDomain"); diff --git a/oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java b/oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java index 16c82c43b..a8208fb65 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java @@ -112,6 +112,7 @@ public void addScopeSequence(List... scopes) { } @Override + @SuppressWarnings("unchecked") public LowLevelHttpRequest buildRequest(final String method, final String url) { MockLowLevelHttpRequest request = new MockLowLevelHttpRequest(url) { diff --git a/oauth2_http/pom.xml b/oauth2_http/pom.xml index 91355a51f..b30f7cece 100644 --- a/oauth2_http/pom.xml +++ b/oauth2_http/pom.xml @@ -230,6 +230,11 @@ com.google.guava guava + + com.google.errorprone + error_prone_annotations + compile + junit junit diff --git a/pom.xml b/pom.xml index ae7bfa08a..c2e887e37 100644 --- a/pom.xml +++ b/pom.xml @@ -71,6 +71,7 @@ false 1.8.2 1.10.4 + 2.18.0 @@ -136,6 +137,12 @@ test-jar testlib + + com.google.errorprone + error_prone_annotations + ${project.error-prone.version} + compile + @@ -232,7 +239,6 @@ 1.8 1.8 UTF-8 - -Xlint:unchecked