Bug 1280382 - Catch ClassCastException that may occur on return from generic method r=mcomella
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 05 Jul 2016 09:29:30 -0700
changeset 305411 77a5e8e87f91113dcf6cb15fdc83a184cc237e48
parent 305410 a35a15008f0c37488cfc5f907f6d553aab028eb8
child 305412 e2ddf53209916302a81ca331f88b4df8df0ca7c7
push id20045
push userahunt@mozilla.com
push dateTue, 19 Jul 2016 01:47:29 +0000
treeherderfx-team@77a5e8e87f91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1280382
milestone50.0a1
Bug 1280382 - Catch ClassCastException that may occur on return from generic method r=mcomella MozReview-Commit-ID: BfiAMAEY1jY
mobile/android/thirdparty/com/adjust/sdk/ActivityHandler.java
--- a/mobile/android/thirdparty/com/adjust/sdk/ActivityHandler.java
+++ b/mobile/android/thirdparty/com/adjust/sdk/ActivityHandler.java
@@ -708,21 +708,43 @@ public class ActivityHandler extends Han
         packageHandler.sendFirstPackage();
 
         if (updateActivityState(System.currentTimeMillis())) {
             writeActivityState();
         }
     }
 
     private void readActivityState() {
-        activityState = Util.readObject(adjustConfig.context, ACTIVITY_STATE_FILENAME, ACTIVITY_STATE_NAME);
+        try {
+	    /**
+             * Mozilla:
+             * readObject is a generic object, and can therefore return arbitrary generic objects
+             * that might not match the expected type. Therefore there will be an implicit cast
+	     * here, which can fail. Therefore we have to add the catch (ClassCastException)
+             * Note: this has been fixed in upstream, we only need this for the version we are still shipping.
+             */
+            activityState = Util.readObject(adjustConfig.context, ACTIVITY_STATE_FILENAME, ACTIVITY_STATE_NAME);
+        } catch (ClassCastException e) {
+            activityState = null;
+        }
     }
 
     private void readAttribution() {
-        attribution = Util.readObject(adjustConfig.context, ATTRIBUTION_FILENAME, ATTRIBUTION_NAME);
+        try {
+	    /**
+             * Mozilla: (same as in readActivityState() )
+             * readObject is a generic object, and can therefore return arbitrary generic objects
+             * that might not match the expected type. Therefore there will be an implicit cast
+	     * here, which can fail. Therefore we have to add the catch (ClassCastException)
+             * Note: this has been fixed in upstream, we only need this for the version we are still shipping.
+             */
+            attribution = Util.readObject(adjustConfig.context, ATTRIBUTION_FILENAME, ATTRIBUTION_NAME);
+        } catch (ClassCastException e) {
+            activityState = null;
+        }
     }
 
     private void writeActivityState() {
         Util.writeObject(activityState, adjustConfig.context, ACTIVITY_STATE_FILENAME, ACTIVITY_STATE_NAME);
     }
 
     private void writeAttribution() {
         Util.writeObject(attribution, adjustConfig.context, ATTRIBUTION_FILENAME, ATTRIBUTION_NAME);