never have null Apks in InstallManagerService

In order to avoid having null guards making the code ugly, use a "blank"
instance of Apk which will work for the various comparisons.  This fixes
this crash:

fixes #688

java.lang.NullPointerException
	at org.fdroid.fdroid.installer.InstallManagerService$4.onReceive(InstallManagerService.java:243)
	at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
	at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
	at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:136)
	at android.app.ActivityThread.main(ActivityThread.java:5001)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:515)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
	at dalvik.system.NativeStart.main(Native Method)
This commit is contained in:
Hans-Christoph Steiner 2016-06-09 16:06:48 +02:00
parent e285fd6f38
commit 5523a443f8

View File

@ -459,11 +459,17 @@ public class InstallManagerService extends Service {
return ACTIVE_APPS.get(getApkFromActive(urlString).packageName);
}
/**
* Remove the URL from this service, and return the {@link Apk}. This returns
* an empty {@code Apk} instance if we get a null one so the code doesn't need
* lots of null guards.
*/
private static Apk removeFromActive(String urlString) {
Apk apk = ACTIVE_APKS.remove(urlString);
if (apk != null) {
ACTIVE_APPS.remove(apk.packageName);
if (apk == null) {
return new Apk();
}
ACTIVE_APPS.remove(apk.packageName);
return apk;
}