Bug 1249288 - Don't call SearchEngineManager change callback if it's null. r=margaret
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 23 Feb 2016 18:11:57 -0800
changeset 290805 afb10f688cdd975aa0986cc7e943fd1a4dc83ea4
parent 290804 6ecd4b60ef8ad9fe5517eff40ba4810ca6069a52
child 290806 0568d580c4a79282dd99b3dd8e4013136e1eb794
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs1249288
milestone48.0a1
Bug 1249288 - Don't call SearchEngineManager change callback if it's null. r=margaret The callback may be null if setChangeCallback is never called and would cause a crash. MozReview-Commit-ID: BNd16Db1A8Q
mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
--- a/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/search/SearchEngineManager.java
@@ -1,16 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.search;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import android.util.Log;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.Locales;
@@ -58,17 +59,17 @@ public class SearchEngineManager impleme
 
     // This should go through GeckoInterface to get the UA, but the search activity
     // doesn't use a GeckoView yet. Until it does, get the UA directly.
     private static final String USER_AGENT = HardwareUtils.isTablet() ?
         AppConstants.USER_AGENT_FENNEC_TABLET : AppConstants.USER_AGENT_FENNEC_MOBILE;
 
     private Context context;
     private Distribution distribution;
-    private SearchEngineCallback changeCallback;
+    @Nullable private SearchEngineCallback changeCallback;
     private SearchEngine engine;
 
     // Cached version of default locale included in Gecko chrome manifest.
     // This should only be accessed from the background thread.
     private String fallbackLocale;
 
     // Cached version of default locale included in Distribution preferences.
     // This should only be accessed from the background thread.
@@ -132,23 +133,25 @@ public class SearchEngineManager impleme
         }
 
         getDefaultEngine(changeCallback);
     }
 
     /**
      * Runs a SearchEngineCallback on the main thread.
      */
-    private void runCallback(final SearchEngine engine, final SearchEngineCallback callback) {
+    private void runCallback(final SearchEngine engine, @Nullable final SearchEngineCallback callback) {
         ThreadUtils.postToUiThread(new Runnable() {
             @Override
             public void run() {
                 // Cache engine for future calls to getEngine.
                 SearchEngineManager.this.engine = engine;
-                callback.execute(engine);
+                if (callback != null) {
+                    callback.execute(engine);
+                }
             }
         });
     }
 
     /**
      * This method finds and creates the default search engine. It will first look for
      * the default engine name, then create the engine from that name.
      *