Skip to content

Commit

Permalink
fix: Remove -Xlint:unchecked, suppress all existing violations, add @…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
sinelaw and Noam Lewis authored Nov 21, 2023
1 parent 47d9a6e commit 04dfd40
Show file tree
Hide file tree
Showing 36 changed files with 196 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,11 +155,13 @@ protected Builder(AppEngineCredentials credentials) {
this.appIdentityService = credentials.appIdentityService;
}

@CanIgnoreReturnValue
public Builder setScopes(Collection<String> scopes) {
this.scopes = scopes;
return this;
}

@CanIgnoreReturnValue
public Builder setAppIdentityService(AppIdentityService appIdentityService) {
this.appIdentityService = appIdentityService;
return this;
Expand Down
5 changes: 5 additions & 0 deletions appengine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,10 @@
<type>test-jar</type>
<classifier>testlib</classifier>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
5 changes: 5 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AccessToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,18 +159,21 @@ 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(" "));
}
return this;
}

@CanIgnoreReturnValue
public Builder setScopes(List<String> scopes) {
if (scopes == null) {
this.scopes = new ArrayList<>();
Expand All @@ -180,6 +184,7 @@ public Builder setScopes(List<String> scopes) {
return this;
}

@CanIgnoreReturnValue
public Builder setExpirationTime(Date expirationTime) {
this.expirationTime = expirationTime;
return this;
Expand Down
10 changes: 10 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AwsRequestSignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.google.auth.oauth2;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -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<String, String> 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;
Expand Down
3 changes: 3 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/AwsRequestSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -298,11 +299,13 @@ private Builder(
this.region = region;
}

@CanIgnoreReturnValue
Builder setRequestPayload(String requestPayload) {
this.requestPayload = requestPayload;
return this;
}

@CanIgnoreReturnValue
Builder setAdditionalHeaders(Map<String, String> additionalHeaders) {
if (additionalHeaders.containsKey("date") && additionalHeaders.containsKey("x-amz-date")) {
throw new IllegalArgumentException("One of {date, x-amz-date} can be specified, not both.");
Expand Down
3 changes: 3 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/ClientId.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -131,6 +132,7 @@ protected Builder(CloudShellCredentials credentials) {
this.authPort = credentials.authPort;
}

@CanIgnoreReturnValue
public Builder setAuthPort(int authPort) {
this.authPort = authPort;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> scopes) {
this.scopes = scopes;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AccessBoundaryRule> rule) {
accessBoundaryRules = new ArrayList<>(checkNotNull(rule));
return this;
}

@CanIgnoreReturnValue
public CredentialAccessBoundary.Builder addRule(AccessBoundaryRule rule) {
if (accessBoundaryRules == null) {
accessBoundaryRules = new ArrayList<>();
Expand Down Expand Up @@ -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;
Expand All @@ -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<String> availablePermissions) {
this.availablePermissions = new ArrayList<>(checkNotNull(availablePermissions));
return this;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 04dfd40

Please sign in to comment.