Bug 1061032 - "crash in java.lang.NullPointerException: at org.mozilla.gecko.ChromeCast$2.onConnected(ChromeCast.java)" [r=mark.finkle]
authorwesj <wjohnston@mozilla.com>
Thu, 02 Oct 2014 11:27:00 -0700
changeset 209401 a259ef6f66d5bfbf088be05bdc5a7759fb21be34
parent 209400 ce37c5e7488253ad27bf05c377f3866f637188f0
child 209402 50565aa7489248079ef92f119c3e3b163c596ac0
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmark.finkle
bugs1061032
milestone35.0a1
Bug 1061032 - "crash in java.lang.NullPointerException: at org.mozilla.gecko.ChromeCast$2.onConnected(ChromeCast.java)" [r=mark.finkle]
mobile/android/base/ChromeCast.java
--- a/mobile/android/base/ChromeCast.java
+++ b/mobile/android/base/ChromeCast.java
@@ -188,17 +188,18 @@ class ChromeCast implements GeckoMediaPl
             public void onApplicationDisconnected(int errorCode) { }
         });
 
         apiClient = new GoogleApiClient.Builder(context)
             .addApi(Cast.API, apiOptionsBuilder.build())
             .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                 @Override
                 public void onConnected(Bundle connectionHint) {
-                    if (!apiClient.isConnected()) {
+                    // Sometimes apiClient is null here. See bug 1061032
+                    if (apiClient != null && !apiClient.isConnected()) {
                         debug("Connection failed");
                         callback.sendError("Not connected");
                         return;
                     }
 
                     // Launch the media player app and launch this url once its loaded
                     try {
                         Cast.CastApi.launchApplication(apiClient, CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID, true)
@@ -423,17 +424,18 @@ class ChromeCast implements GeckoMediaPl
                 public void onApplicationDisconnected(int errorCode) { }
             });
 
         apiClient = new GoogleApiClient.Builder(context)
             .addApi(Cast.API, apiOptionsBuilder.build())
             .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                     @Override
                     public void onConnected(Bundle connectionHint) {
-                        if (!apiClient.isConnected()) {
+                        // Sometimes apiClient is null here. See bug 1061032
+                        if (apiClient == null || !apiClient.isConnected()) {
                             return;
                         }
 
                         // Launch the media player app and launch this url once its loaded
                         try {
                             Cast.CastApi.launchApplication(apiClient, MIRROR_RECIEVER_APP_ID, true)
                                 .setResultCallback(new MirrorCallback(callback));
                         } catch (Exception e) {