Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB9E1DDA5 for ; Tue, 2 Oct 2012 14:02:54 +0000 (UTC) Received: (qmail 61767 invoked by uid 500); 2 Oct 2012 14:02:54 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 61744 invoked by uid 500); 2 Oct 2012 14:02:54 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 61708 invoked by uid 99); 2 Oct 2012 14:02:54 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Oct 2012 14:02:54 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 49E7F1EE24; Tue, 2 Oct 2012 14:02:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/2] android commit: Fix NPE caused by NetworkManager sending update before JS is ready. Message-Id: <20121002140254.49E7F1EE24@tyr.zones.apache.org> Date: Tue, 2 Oct 2012 14:02:54 +0000 (UTC) Fix NPE caused by NetworkManager sending update before JS is ready. This was happening for me when the device has been sleeping long enough to turn its networking off, and I start an app via adb. Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/5289d569 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/5289d569 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/5289d569 Branch: refs/heads/master Commit: 5289d569b06437b5b6fdd536b693f1a2d04ef224 Parents: 6f873ff Author: Andrew Grieve Authored: Tue Oct 2 09:49:53 2012 -0400 Committer: Andrew Grieve Committed: Tue Oct 2 10:02:42 2012 -0400 ---------------------------------------------------------------------- .../org/apache/cordova/NativeToJsMessageQueue.java | 4 ++++ .../src/org/apache/cordova/NetworkManager.java | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/5289d569/framework/src/org/apache/cordova/NativeToJsMessageQueue.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java index 934088a..54c6eed 100755 --- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java +++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java @@ -219,6 +219,10 @@ public class NativeToJsMessageQueue { * Add a JavaScript statement to the list. */ public void addPluginResult(PluginResult result, String callbackId) { + if (callbackId == null) { + Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable()); + return; + } // Don't send anything if there is no result and there is no need to // clear the callbacks. boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal(); http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/5289d569/framework/src/org/apache/cordova/NetworkManager.java ---------------------------------------------------------------------- diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java index 8c8c400..f473abe 100755 --- a/framework/src/org/apache/cordova/NetworkManager.java +++ b/framework/src/org/apache/cordova/NetworkManager.java @@ -206,9 +206,11 @@ public class NetworkManager extends Plugin { * @param connection the network info to set as navigator.connection */ private void sendUpdate(String type) { - PluginResult result = new PluginResult(PluginResult.Status.OK, type); - result.setKeepCallback(true); - this.success(result, this.connectionCallbackId); + if (connectionCallbackId != null) { + PluginResult result = new PluginResult(PluginResult.Status.OK, type); + result.setKeepCallback(true); + this.success(result, this.connectionCallbackId); + } webView.postMessage("networkconnection", type); }