37
37
import com .google .auth .http .AuthHttpConstants ;
38
38
import com .google .common .annotations .VisibleForTesting ;
39
39
import com .google .common .base .MoreObjects ;
40
- import com .google .common .base .Preconditions ;
41
40
import com .google .common .collect .ImmutableMap ;
42
41
import com .google .common .collect .Iterables ;
43
42
import java .io .IOException ;
@@ -131,7 +130,10 @@ public void getRequestMetadata(
131
130
super .getRequestMetadata (uri , executor , callback );
132
131
return ;
133
132
}
134
- metadata = Preconditions .checkNotNull (requestMetadata , "cached requestMetadata" );
133
+ if (requestMetadata == null ) {
134
+ throw new NullPointerException ("cached requestMetadata" );
135
+ }
136
+ metadata = requestMetadata ;
135
137
}
136
138
callback .onSuccess (metadata );
137
139
}
@@ -146,7 +148,10 @@ public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException
146
148
if (shouldRefresh ()) {
147
149
refresh ();
148
150
}
149
- return Preconditions .checkNotNull (requestMetadata , "requestMetadata" );
151
+ if (requestMetadata == null ) {
152
+ throw new NullPointerException ("requestMetadata" );
153
+ }
154
+ return requestMetadata ;
150
155
}
151
156
}
152
157
@@ -156,9 +161,11 @@ public void refresh() throws IOException {
156
161
synchronized (lock ) {
157
162
requestMetadata = null ;
158
163
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 ());
162
169
if (changeListeners != null ) {
163
170
for (CredentialsChangedListener listener : changeListeners ) {
164
171
listener .onChanged (this );
@@ -214,8 +221,10 @@ private boolean shouldRefresh() {
214
221
* <p>Throws IllegalStateException if not overridden since direct use of OAuth2Credentials is only
215
222
* for temporary or non-refreshing access tokens.
216
223
*
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.
219
228
*/
220
229
public AccessToken refreshAccessToken () throws IOException {
221
230
throw new IllegalStateException (
@@ -230,7 +239,7 @@ public AccessToken refreshAccessToken() throws IOException {
230
239
* <p>This is called when token content changes, such as when the access token is refreshed. This
231
240
* is typically used by code caching the access token.
232
241
*
233
- * @param listener The listener to be added.
242
+ * @param listener the listener to be added
234
243
*/
235
244
public final void addChangeListener (CredentialsChangedListener listener ) {
236
245
synchronized (lock ) {
0 commit comments