Bug 1273686 - Don't crash on invalid sequence number argument in core ping. r=ahunt draft
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 17 May 2016 17:10:56 -0700
changeset 368039 4b922cc86caddcd5c92310d9220fcf06e7d734f2
parent 367617 a7e57536b61c186973b8ef1a5efccf630e60d068
child 368040 bf95b42c4a2f01f424f6f2cdbfedad728715730d
push id18420
push usermichael.l.comella@gmail.com
push dateWed, 18 May 2016 00:11:03 +0000
reviewersahunt
bugs1273686
milestone49.0a1
Bug 1273686 - Don't crash on invalid sequence number argument in core ping. r=ahunt MozReview-Commit-ID: A2nNBgQz5yr
mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/pingbuilders/TelemetryCorePingBuilder.java
@@ -9,16 +9,17 @@ package org.mozilla.gecko.telemetry.ping
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.WorkerThread;
 import android.text.TextUtils;
 
+import android.util.Log;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.search.SearchEngine;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 import org.mozilla.gecko.telemetry.TelemetryConstants;
 import org.mozilla.gecko.telemetry.TelemetryPing;
 import org.mozilla.gecko.util.DateUtil;
@@ -33,16 +34,17 @@ import java.util.concurrent.TimeUnit;
 
 /**
  * Builds a {@link TelemetryPing} representing a core ping.
  *
  * See https://gecko.readthedocs.org/en/latest/toolkit/components/telemetry/telemetry/core-ping.html
  * for details on the core ping.
  */
 public class TelemetryCorePingBuilder extends TelemetryPingBuilder {
+    private static final String LOGTAG = StringUtils.safeSubstring(TelemetryCorePingBuilder.class.getSimpleName(), 0, 23);
 
     private static final String NAME = "core";
     private static final int VERSION_VALUE = 6; // For version history, see toolkit/components/telemetry/docs/core-ping.rst
     private static final String OS_VALUE = "Android";
 
     private static final String ARCHITECTURE = "arch";
     private static final String CLIENT_ID = "clientId";
     private static final String DEFAULT_SEARCH_ENGINE = "defaultSearch";
@@ -160,17 +162,19 @@ public class TelemetryCorePingBuilder ex
         return this;
     }
 
     /**
      * @param seq a positive sequence number.
      */
     public TelemetryCorePingBuilder setSequenceNumber(final int seq) {
         if (seq < 0) {
-            throw new IllegalArgumentException("Expected positive sequence number. Recived: " + seq);
+            // Since this is an increasing value, it's possible we can overflow into negative values and get into a
+            // crash loop so we don't crash on invalid arg - we can investigate if we see negative values on the server.
+            Log.w(LOGTAG, "Expected positive sequence number. Received: " + seq);
         }
         payload.put(SEQ, seq);
         return this;
     }
 
     /**
      * Gets the sequence number from shared preferences and increments it in the prefs. This method
      * is not thread safe.