Skip to content

Commit 39228f4

Browse files
author
Yaniv Inbar
committed
[api] Exception -> IOException
https://codereview.appspot.com/6699045/
1 parent 44c2ebc commit 39228f4

48 files changed

Lines changed: 217 additions & 294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

google-api-client-android/src/main/java/com/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.api.client.googleapis.extensions.android.gms.auth;
1616

17+
import com.google.android.gms.auth.GoogleAuthException;
1718
import com.google.android.gms.auth.GoogleAuthUtil;
1819
import com.google.android.gms.common.AccountPicker;
1920
import com.google.api.client.googleapis.extensions.android.accounts.GoogleAccountManager;
@@ -35,6 +36,11 @@
3536
/**
3637
* Manages authorization and account selection for Google accounts.
3738
*
39+
* <p>
40+
* Any thrown {@link GoogleAuthException} when fetching a token would be wrapped inside of an
41+
* {@link IOException}.
42+
* </p>
43+
*
3844
* @since 1.12
3945
* @author Yaniv Inbar
4046
*/
@@ -174,7 +180,7 @@ public final Intent newChooseAccountIntent() {
174180
* Must be run from a background thread, not the main UI thread.
175181
* </p>
176182
*/
177-
public final String getToken() throws Exception {
183+
public final String getToken() throws IOException, GoogleAuthException {
178184
BackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
179185
while (true) {
180186
try {
@@ -201,9 +207,15 @@ class RequestHandler implements HttpExecuteInterceptor, HttpUnsuccessfulResponse
201207
boolean received401;
202208
String token;
203209

204-
public void intercept(HttpRequest request) throws Exception {
205-
token = getToken();
206-
request.getHeaders().setAuthorization("Bearer " + token);
210+
public void intercept(HttpRequest request) throws IOException {
211+
try {
212+
token = getToken();
213+
request.getHeaders().setAuthorization("Bearer " + token);
214+
} catch (GoogleAuthException exception) {
215+
IOException e = new IOException();
216+
e.initCause(exception);
217+
throw e;
218+
}
207219
}
208220

209221
public boolean handleResponse(

google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/AppIdentityCredential.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ public void initialize(HttpRequest request) throws IOException {
9393
* Intercept the request by using the access token obtained from the {@link AppIdentityService}.
9494
*
9595
* <p>
96-
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
97-
* {@link java.io.IOException}. In prior version {@link AppIdentityServiceFailureException} was
98-
* wrapped with an {@link Exception}, but now it is no longer wrapped.
96+
* Upgrade warning: in prior version 1.11 {@link AppIdentityServiceFailureException} was wrapped
97+
* with an {@link IOException}, but now it is no longer wrapped because it is a
98+
* {@link RuntimeException}.
9999
* </p>
100100
*/
101101
@Override
102-
public void intercept(HttpRequest request) throws Exception {
102+
public void intercept(HttpRequest request) throws IOException {
103103
String accessToken = appIdentityService.getAccessToken(scopes).getAccessToken();
104104
BearerToken.authorizationHeaderAccessMethod().intercept(request, accessToken);
105105
}

google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/subscriptions/AppEngineSubscriptionStore.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,46 +69,44 @@ private Blob serialize(Object obj) throws IOException {
6969
try {
7070
new ObjectOutputStream(baos).writeObject(obj);
7171
return new Blob(baos.toByteArray());
72-
} catch (IOException ex) {
73-
throw new IOException("Failed to serialize object", ex);
7472
} finally {
7573
baos.close();
7674
}
7775
}
7876

7977
/** Deserializes the specified object from a Blob using an {@link ObjectInputStream}. */
8078
@SuppressWarnings("unchecked")
81-
private <T> T deserialize(Blob data, Class<T> dataType) throws Exception {
79+
private <T> T deserialize(Blob data, Class<T> dataType) throws IOException {
8280
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes());
8381
try {
8482
Object obj = new ObjectInputStream(bais).readObject();
8583
if (!dataType.isAssignableFrom(obj.getClass())) {
8684
return null;
8785
}
8886
return (T) obj;
89-
} catch (IOException ex) {
90-
throw new IOException("Failed to deserialize object", ex);
87+
} catch (ClassNotFoundException exception) {
88+
throw new IOException("Failed to deserialize object", exception);
9189
} finally {
9290
bais.close();
9391
}
9492
}
9593

9694
/** Parses the specified Entity and returns the contained Subscription object. */
97-
private Subscription getSubscriptionFromEntity(Entity entity) throws Exception {
95+
private Subscription getSubscriptionFromEntity(Entity entity) throws IOException {
9896
Blob serializedSubscription = (Blob) entity.getProperty(FIELD_SUBSCRIPTION);
9997
return deserialize(serializedSubscription, Subscription.class);
10098
}
10199

102100
@Override
103-
public void storeSubscription(Subscription subscription) throws Exception {
101+
public void storeSubscription(Subscription subscription) throws IOException {
104102
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
105103
Entity entity = new Entity(KIND, subscription.getSubscriptionID());
106104
entity.setProperty(FIELD_SUBSCRIPTION, serialize(subscription));
107105
service.put(entity);
108106
}
109107

110108
@Override
111-
public void removeSubscription(Subscription subscription) throws Exception {
109+
public void removeSubscription(Subscription subscription) throws IOException {
112110
if (subscription == null) {
113111
return;
114112
}
@@ -118,7 +116,7 @@ public void removeSubscription(Subscription subscription) throws Exception {
118116
}
119117

120118
@Override
121-
public List<Subscription> listSubscriptions() throws Exception {
119+
public List<Subscription> listSubscriptions() throws IOException {
122120
List<Subscription> list = Lists.newArrayList();
123121
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
124122
PreparedQuery results = service.prepare(new Query(KIND));
@@ -131,7 +129,7 @@ public List<Subscription> listSubscriptions() throws Exception {
131129
}
132130

133131
@Override
134-
public Subscription getSubscription(String subscriptionID) throws Exception {
132+
public Subscription getSubscription(String subscriptionID) throws IOException {
135133
try {
136134
DatastoreService service = DatastoreServiceFactory.getDatastoreService();
137135
Entity entity = service.get(KeyFactory.createKey(KIND, subscriptionID));

google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/subscriptions/CachedAppEngineSubscriptionStore.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.google.appengine.api.memcache.MemcacheService;
2121
import com.google.appengine.api.memcache.MemcacheServiceFactory;
2222

23+
import java.io.IOException;
24+
2325
/**
2426
* Implementation of a persistent {@link SubscriptionStore} making use of native DataStore and
2527
* the Memcache API on AppEngine.
@@ -52,19 +54,19 @@ public final class CachedAppEngineSubscriptionStore extends AppEngineSubscriptio
5254
CachedAppEngineSubscriptionStore.class.getCanonicalName());
5355

5456
@Override
55-
public void removeSubscription(Subscription subscription) throws Exception {
57+
public void removeSubscription(Subscription subscription) throws IOException {
5658
super.removeSubscription(subscription);
5759
memCache.delete(subscription.getSubscriptionID());
5860
}
5961

6062
@Override
61-
public void storeSubscription(Subscription subscription) throws Exception {
63+
public void storeSubscription(Subscription subscription) throws IOException {
6264
super.storeSubscription(subscription);
6365
memCache.put(subscription.getSubscriptionID(), subscription);
6466
}
6567

6668
@Override
67-
public Subscription getSubscription(String subscriptionID) throws Exception {
69+
public Subscription getSubscription(String subscriptionID) throws IOException {
6870
if (memCache.contains(subscriptionID)) {
6971
return (Subscription) memCache.get(subscriptionID);
7072
}

google-api-client-java6/src/main/java/com/google/api/client/googleapis/extensions/java6/auth/oauth2/GooglePromptReceiver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.google.api.client.extensions.java6.auth.oauth2.AbstractPromptReceiver;
1818
import com.google.api.client.googleapis.auth.oauth2.GoogleOAuthConstants;
1919

20+
import java.io.IOException;
21+
2022
/**
2123
* Google OAuth 2.0 abstract verification code receiver that prompts user to paste the code copied
2224
* from the browser.
@@ -31,7 +33,7 @@
3133
public class GooglePromptReceiver extends AbstractPromptReceiver {
3234

3335
@Override
34-
public String getRedirectUri() throws Exception {
36+
public String getRedirectUri() throws IOException {
3537
return GoogleOAuthConstants.OOB_REDIRECT_URI;
3638
}
3739
}

google-api-client-servlet/src/main/java/com/google/api/client/googleapis/extensions/servlet/subscriptions/AbstractWebHookServlet.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.google.api.client.googleapis.subscriptions.SubscriptionHeaders;
1818
import com.google.api.client.googleapis.subscriptions.SubscriptionStore;
1919
import com.google.api.client.googleapis.subscriptions.UnparsedNotification;
20-
import com.google.common.base.Throwables;
2120

2221
import java.io.IOException;
2322
import java.io.InputStream;
@@ -147,9 +146,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
147146
if (!notification.deliverNotification(getSubscriptionStore())) {
148147
sendUnsubscribeResponse(resp, notification);
149148
}
150-
} catch (Exception e) {
151-
Throwables.propagateIfPossible(e, IOException.class, ServletException.class);
152-
throw new ServletException(e);
153149
} finally {
154150
contentStream.close();
155151
}

google-api-client/src/main/java/com/google/api/client/googleapis/GoogleHeaders.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,9 @@ public class GoogleHeaders extends HttpHeaders {
3434
public static final PercentEscaper SLUG_ESCAPER =
3535
new PercentEscaper(" !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~", false);
3636

37-
/**
38-
* {@code "GData-Version"} header.
39-
*
40-
* @deprecated (scheduled to be made private in 1.12) Use {@link #getGDataVersion} or
41-
* {@link #setGDataVersion}
42-
*/
43-
@Deprecated
37+
/** {@code "GData-Version"} header. */
4438
@Key("GData-Version")
45-
public String gdataVersion;
39+
private String gdataVersion;
4640

4741
/**
4842
* Escaped {@code "Slug"} header value, which must be escaped using {@link #SLUG_ESCAPER}.

google-api-client/src/main/java/com/google/api/client/googleapis/MethodOverride.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.api.client.http.HttpRequestInitializer;
2323
import com.google.common.base.Preconditions;
2424

25+
import java.io.IOException;
2526
import java.util.EnumSet;
2627

2728
/**
@@ -97,7 +98,7 @@ public void initialize(HttpRequest request) {
9798
request.setInterceptor(this);
9899
}
99100

100-
public void intercept(HttpRequest request) throws Exception {
101+
public void intercept(HttpRequest request) throws IOException {
101102
if (overrideThisMethod(request)) {
102103
String requestMethod = request.getRequestMethod();
103104
request.setRequestMethod(HttpMethods.POST);
@@ -109,7 +110,7 @@ public void intercept(HttpRequest request) throws Exception {
109110
}
110111
}
111112

112-
private boolean overrideThisMethod(HttpRequest request) throws Exception {
113+
private boolean overrideThisMethod(HttpRequest request) throws IOException {
113114
String requestMethod = request.getRequestMethod();
114115
boolean supportsMethod = request.getTransport().supportsMethod(requestMethod);
115116
if (requestMethod.equals(HttpMethods.GET) || requestMethod.equals(HttpMethods.POST)) {

google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/AuthKeyValueParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public String getContentType() {
4747
return "text/plain";
4848
}
4949

50-
public <T> T parse(HttpResponse response, Class<T> dataClass) throws Exception {
50+
public <T> T parse(HttpResponse response, Class<T> dataClass) throws IOException {
5151
response.setContentLoggingLimit(0);
5252
InputStream content = response.getContent();
5353
try {

google-api-client/src/main/java/com/google/api/client/googleapis/auth/clientlogin/ClientLogin.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.google.api.client.util.Key;
2727
import com.google.api.client.util.StringUtils;
2828

29+
import java.io.IOException;
30+
2931
/**
3032
* Client Login authentication method as described in <a
3133
* href="http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html" >ClientLogin for
@@ -162,15 +164,10 @@ public static final class ErrorInfo {
162164
/**
163165
* Authenticates based on the provided field values.
164166
*
165-
* <p>
166-
* Upgrade warning: this method now throws an {@link Exception}. In prior version 1.11 it threw an
167-
* {@link java.io.IOException}.
168-
* </p>
169-
*
170167
* @throws ClientLoginResponseException if the authentication response has an error code, such as
171168
* for a CAPTCHA challenge.
172169
*/
173-
public Response authenticate() throws Exception {
170+
public Response authenticate() throws IOException {
174171
GenericUrl url = serverUrl.clone();
175172
url.appendRawPath("/accounts/ClientLogin");
176173
HttpRequest request =

0 commit comments

Comments
 (0)