Bug 1261995 - Quiet infer NullPointerException warnings. r=mcomella
authorNick Alexander <nalexander@mozilla.com>
Tue, 05 Apr 2016 16:32:01 -0700
changeset 316980 3e85a84c7d68632e1098cc9374787dc8f54ce24f
parent 316979 6b0f8e84b00ceb8db88665a00c0089f467f9136d
child 316981 755a175b3cc735b575a9e3dd4fcfcd4c7a63695c
child 317189 6ddb8429d92077d93cb705f5758d75e028fac86c
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1261995
milestone48.0a1
Bug 1261995 - Quiet infer NullPointerException warnings. r=mcomella MozReview-Commit-ID: C0LPj4kGbPk
mobile/android/services/src/main/java/org/mozilla/gecko/push/autopush/AutopushClient.java
--- 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);
     }