Skip to content
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

fix: replace non-precondition use of Preconditions #539

Merged
merged 3 commits into from
Jan 14, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.auth.http.AuthHttpConstants;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import java.io.IOException;
Expand Down Expand Up @@ -131,7 +130,10 @@ public void getRequestMetadata(
super.getRequestMetadata(uri, executor, callback);
return;
}
metadata = Preconditions.checkNotNull(requestMetadata, "cached requestMetadata");
if (requestMetadata == null) {
throw new NullPointerException("cached requestMetadata");
}
metadata = requestMetadata;
}
callback.onSuccess(metadata);
}
Expand All @@ -146,7 +148,10 @@ public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException
if (shouldRefresh()) {
refresh();
}
return Preconditions.checkNotNull(requestMetadata, "requestMetadata");
if (requestMetadata == null) {
throw new NullPointerException("requestMetadata");
}
return requestMetadata;
}
}

Expand All @@ -156,9 +161,11 @@ public void refresh() throws IOException {
synchronized (lock) {
requestMetadata = null;
temporaryAccess = null;
useAccessToken(
Preconditions.checkNotNull(refreshAccessToken(), "new access token"),
getAdditionalHeaders());
AccessToken accessToken = refreshAccessToken();
if (accessToken == null) {
throw new NullPointerException("new access token");
}
useAccessToken(accessToken, getAdditionalHeaders());
if (changeListeners != null) {
for (CredentialsChangedListener listener : changeListeners) {
listener.onChanged(this);
Expand Down Expand Up @@ -214,8 +221,10 @@ private boolean shouldRefresh() {
* <p>Throws IllegalStateException if not overridden since direct use of OAuth2Credentials is only
* for temporary or non-refreshing access tokens.
*
* @return Refreshed access token.
* @throws IOException from derived implementations
* @return never
* @throws IllegalStateException always. OAuth2Credentials does not support refreshing the access
* token. An instance with a new access token or a derived type that supports refreshing
* should be used instead.
*/
public AccessToken refreshAccessToken() throws IOException {
throw new IllegalStateException(
Expand All @@ -230,7 +239,7 @@ public AccessToken refreshAccessToken() throws IOException {
* <p>This is called when token content changes, such as when the access token is refreshed. This
* is typically used by code caching the access token.
*
* @param listener The listener to be added.
* @param listener the listener to be added
*/
public final void addChangeListener(CredentialsChangedListener listener) {
synchronized (lock) {
Expand Down