Bug 1261995 - Quiet infer NullPointerException warnings. r?mcomella
MozReview-Commit-ID: C0LPj4kGbPk
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/push/autopush/AutopushClient.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/push/autopush/AutopushClient.java
@@ -55,16 +55,19 @@ public class AutopushClient {
protected static final String[] REGISTER_USER_AGENT_RESPONSE_REQUIRED_STRING_FIELDS = new String[] { JSON_KEY_UAID, JSON_KEY_SECRET, JSON_KEY_CHANNEL_ID, JSON_KEY_ENDPOINT };
protected static final String[] REGISTER_CHANNEL_RESPONSE_REQUIRED_STRING_FIELDS = new String[] { JSON_KEY_CHANNEL_ID, JSON_KEY_ENDPOINT };
public static final String JSON_KEY_CODE = "code";
public static final String JSON_KEY_ERRNO = "errno";
public static final String JSON_KEY_ERROR = "error";
public static final String JSON_KEY_MESSAGE = "message";
+ protected static final String[] requiredErrorStringFields = { JSON_KEY_ERROR, JSON_KEY_MESSAGE };
+ protected static final String[] requiredErrorLongFields = { JSON_KEY_CODE, JSON_KEY_ERRNO };
+
/**
* The server's URI.
* <p>
* We assume throughout that this ends with a trailing slash (and guarantee as
* much in the constructor).
*/
public final String serverURI;
@@ -131,29 +134,30 @@ public class AutopushClient {
* @return response's HTTP status code.
* @throws AutopushClientException
*/
public static int validateResponse(HttpResponse response) throws AutopushClientException {
final int status = response.getStatusLine().getStatusCode();
if (200 <= status && status <= 299) {
return status;
}
- int code;
- int errno;
+ long code;
+ long errno;
String error;
String message;
String info;
ExtendedJSONObject body;
try {
body = new SyncStorageResponse(response).jsonObjectBody();
// TODO: The service doesn't do the right thing yet :(
// body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
- // body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
- code = body.getLong(JSON_KEY_CODE).intValue();
- errno = body.getLong(JSON_KEY_ERRNO).intValue();
+ body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
+ // Would throw above if missing; the -1 defaults quiet NPE warnings.
+ code = body.getLong(JSON_KEY_CODE, -1);
+ errno = body.getLong(JSON_KEY_ERRNO, -1);
error = body.getString(JSON_KEY_ERROR);
message = body.getString(JSON_KEY_MESSAGE);
} catch (Exception e) {
throw new AutopushClientException.AutopushClientMalformedResponseException(response);
}
throw new AutopushClientException.AutopushClientRemoteException(response, code, errno, error, message, body);
}