Skip to content

Commit f2ab4f1

Browse files
authored
fix: replace non-precondition use of Preconditions (#539)
* replace non-precondition use of Preconditions * format
1 parent 75d85b3 commit f2ab4f1

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import com.google.auth.http.AuthHttpConstants;
3838
import com.google.common.annotations.VisibleForTesting;
3939
import com.google.common.base.MoreObjects;
40-
import com.google.common.base.Preconditions;
4140
import com.google.common.collect.ImmutableMap;
4241
import com.google.common.collect.Iterables;
4342
import java.io.IOException;
@@ -131,7 +130,10 @@ public void getRequestMetadata(
131130
super.getRequestMetadata(uri, executor, callback);
132131
return;
133132
}
134-
metadata = Preconditions.checkNotNull(requestMetadata, "cached requestMetadata");
133+
if (requestMetadata == null) {
134+
throw new NullPointerException("cached requestMetadata");
135+
}
136+
metadata = requestMetadata;
135137
}
136138
callback.onSuccess(metadata);
137139
}
@@ -146,7 +148,10 @@ public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException
146148
if (shouldRefresh()) {
147149
refresh();
148150
}
149-
return Preconditions.checkNotNull(requestMetadata, "requestMetadata");
151+
if (requestMetadata == null) {
152+
throw new NullPointerException("requestMetadata");
153+
}
154+
return requestMetadata;
150155
}
151156
}
152157

@@ -156,9 +161,11 @@ public void refresh() throws IOException {
156161
synchronized (lock) {
157162
requestMetadata = null;
158163
temporaryAccess = null;
159-
useAccessToken(
160-
Preconditions.checkNotNull(refreshAccessToken(), "new access token"),
161-
getAdditionalHeaders());
164+
AccessToken accessToken = refreshAccessToken();
165+
if (accessToken == null) {
166+
throw new NullPointerException("new access token");
167+
}
168+
useAccessToken(accessToken, getAdditionalHeaders());
162169
if (changeListeners != null) {
163170
for (CredentialsChangedListener listener : changeListeners) {
164171
listener.onChanged(this);
@@ -214,8 +221,10 @@ private boolean shouldRefresh() {
214221
* <p>Throws IllegalStateException if not overridden since direct use of OAuth2Credentials is only
215222
* for temporary or non-refreshing access tokens.
216223
*
217-
* @return Refreshed access token.
218-
* @throws IOException from derived implementations
224+
* @return never
225+
* @throws IllegalStateException always. OAuth2Credentials does not support refreshing the access
226+
* token. An instance with a new access token or a derived type that supports refreshing
227+
* should be used instead.
219228
*/
220229
public AccessToken refreshAccessToken() throws IOException {
221230
throw new IllegalStateException(
@@ -230,7 +239,7 @@ public AccessToken refreshAccessToken() throws IOException {
230239
* <p>This is called when token content changes, such as when the access token is refreshed. This
231240
* is typically used by code caching the access token.
232241
*
233-
* @param listener The listener to be added.
242+
* @param listener the listener to be added
234243
*/
235244
public final void addChangeListener(CredentialsChangedListener listener) {
236245
synchronized (lock) {

0 commit comments

Comments
 (0)