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
This commit is contained in:
Andrzej Hunt 2017-04-18 20:10:44 -07:00
Родитель 324dd505d3
Коммит f1be49c357
2 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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();