From f1be49c35736e5c971b28627e1462d3e50289d4e Mon Sep 17 00:00:00 2001 From: Andrzej Hunt Date: Tue, 18 Apr 2017 20:10:44 -0700 Subject: [PATCH] Bug 1357630 - infer: (NULL_DEREFERENCE) add null-check to getAppEventDispatcher r=nalexander Every single caller of getAppEventDispatcher() and getEventDispatcher() assumes a non-null return value, so let's make sure we're actually returning a non-null value. This commit doesn't effectively change runtime behaviour (any previously NPE crashes will now result in a crash due to IllegalStateException), however we now at least have an obvious error message in that situation. In reality, no code should run before onCreate(), so this should realistically never happen - but we should still check to ensure that is the case. (This removes 28 infer NULL_DEREFERENCE warnings.) MozReview-Commit-ID: GhzwKWfkAbD --HG-- extra : rebase_source : f6b13f590b437ebb63e502f774a70164054ecf7e --- .../android/base/java/org/mozilla/gecko/GeckoApp.java | 10 +++++++--- .../src/main/java/org/mozilla/gecko/GeckoAppShell.java | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java index 0555803929d1..799a2592d05b 100644 --- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java +++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java @@ -1886,14 +1886,18 @@ public abstract class GeckoApp } @RobocopTarget - public static EventDispatcher getEventDispatcher() { + public static @NonNull EventDispatcher getEventDispatcher() { final GeckoApp geckoApp = (GeckoApp) GeckoAppShell.getGeckoInterface(); return geckoApp.getAppEventDispatcher(); } @Override - public EventDispatcher getAppEventDispatcher() { - return mLayerView != null ? mLayerView.getEventDispatcher() : null; + public @NonNull EventDispatcher getAppEventDispatcher() { + if (mLayerView == null) { + throw new IllegalStateException("Must not call getAppEventDispatcher() until after onCreate()"); + } + + return mLayerView.getEventDispatcher(); } @Override diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java index bbe9648de49c..39854b292e11 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java @@ -84,6 +84,7 @@ import android.os.ParcelFileDescriptor; import android.os.SystemClock; import android.os.Vibrator; import android.provider.Settings; +import android.support.annotation.NonNull; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -1660,7 +1661,7 @@ public class GeckoAppShell } public interface GeckoInterface { - public EventDispatcher getAppEventDispatcher(); + public @NonNull EventDispatcher getAppEventDispatcher(); public GeckoProfile getProfile(); public Activity getActivity(); public String getDefaultUAString();