Bug 1271020: Add a null check before acting upon applicationContext r=sebastian draft
authorGrigory Kruglov <gkruglov@mozilla.com>
Fri, 06 May 2016 18:35:54 -0700
changeset 364645 b1203f0f16a5a394891debfd5a94dea28868b3d3
parent 364626 738ec20418cc728910419aa60f98ae62b429facf
child 520342 bf27805f8e8d6256a0905f84c47a184b807e160c
push id17517
push usergkruglov@mozilla.com
push dateSat, 07 May 2016 07:08:05 +0000
reviewerssebastian
bugs1271020
milestone49.0a1
Bug 1271020: Add a null check before acting upon applicationContext r=sebastian Pre-rewrite code had a similar check MozReview-Commit-ID: FGqPCOabkqH
mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoNetworkManager.java
@@ -258,16 +258,20 @@ public class GeckoNetworkManager extends
                 throw new IllegalStateException("Unknown current state: " + currentState.name());
         }
     }
 
     /**
      * Update current network state and connection types.
      */
     private void updateNetworkStateAndConnectionType() {
+        if (applicationContext == null) {
+            Log.i(LOGTAG, "applicationContext is null while trying to update network state");
+            return;
+        }
         final ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext.getSystemService(
                 Context.CONNECTIVITY_SERVICE);
         // Type/status getters below all have a defined behaviour for when connectivityManager == null
         if (connectivityManager == null) {
             Log.e(LOGTAG, "ConnectivityManager does not exist.");
         }
         currentConnectionType = NetworkUtils.getConnectionType(connectivityManager);
         currentNetworkStatus = NetworkUtils.getNetworkStatus(connectivityManager);