Bug 880171 - Part 1: return null if unable to retrieve storage in EnvironmentBuilder. r=nalexander, a=lsblakk
authorRichard Newman <rnewman@mozilla.com>
Fri, 07 Jun 2013 10:20:58 -0700
changeset 142932 659227d5485cf09586446aa16f134f26f5f9b825
parent 142931 a04d6f9d11318629d4dcf3e51b3eaabe644a7145
child 142933 54b272e9542fb711a45bb8ec97d9def9d261b283
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander, lsblakk
bugs880171
milestone23.0a2
Bug 880171 - Part 1: return null if unable to retrieve storage in EnvironmentBuilder. r=nalexander, a=lsblakk
mobile/android/base/background/healthreport/EnvironmentBuilder.java
--- a/mobile/android/base/background/healthreport/EnvironmentBuilder.java
+++ b/mobile/android/base/background/healthreport/EnvironmentBuilder.java
@@ -22,19 +22,32 @@ import android.content.Context;
 public class EnvironmentBuilder {
   private static final String LOG_TAG = "GeckoEnvBuilder";
 
   public static ContentProviderClient getContentProviderClient(Context context) {
     ContentResolver cr = context.getContentResolver();
     return cr.acquireContentProviderClient(HealthReportConstants.HEALTH_AUTHORITY);
   }
 
+  /**
+   * Fetch the storage object associated with the provided
+   * {@link ContentProviderClient}. If no storage instance can be found --
+   * perhaps because the {@link ContentProvider} is running in a different
+   * process -- returns <code>null</code>.
+   * 
+   * If the provider is not a {@link HealthReportProvider}, throws a
+   * {@link ClassCastException}, because that would be disastrous.
+   */
   public static HealthReportDatabaseStorage getStorage(ContentProviderClient cpc,
                                                        String profilePath) {
     ContentProvider pr = cpc.getLocalContentProvider();
+    if (pr == null) {
+      Logger.error(LOG_TAG, "Unable to retrieve local content provider. Running in a different process?");
+      return null;
+    }
     try {
       return ((HealthReportProvider) pr).getProfileStorage(profilePath);
     } catch (ClassCastException ex) {
       Logger.error(LOG_TAG, "ContentProvider not a HealthReportProvider!", ex);
       throw ex;
     }
   }