From 4f7f87be0a0487aad19c78a2a44faa1c2f008361 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 29 Jul 2014 23:27:32 -0400 Subject: [PATCH] assign static var FDroidApp.selectedApps only after HashSet is built This should help is there is ever multithreaded access to this variable. This is an unlikely scenario, but the fix is easy. findbugs reported this issue like this: Incorrect lazy initialization and update of static field org.fdroid.fdroid. FDroidApp.selectedApps in org.fdroid.fdroid.views.fragments. SelectLocalAppsFragment.onActivityCreated(Bundle) This method contains an unsynchronized lazy initialization of a static field. After the field is set, the object stored into that location is further updated or accessed. The setting of the field is visible to other threads as soon as it is set. If the futher accesses in the method that set the field serve to initialize the object, then you have a very serious multithreading bug, unless something else prevents any other thread from accessing the stored object until it is fully initialized. --- .../fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java b/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java index 01d037a55..eb944ec94 100644 --- a/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java +++ b/src/org/fdroid/fdroid/views/fragments/SelectLocalAppsFragment.java @@ -112,13 +112,14 @@ public class SelectLocalAppsFragment extends ListFragment // build list of existing apps from what is on the file system if (FDroidApp.selectedApps == null) { - FDroidApp.selectedApps = new HashSet(); + HashSet selectedApps = new HashSet(); for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) { if (filename.matches(".*\\.apk")) { String packageName = filename.substring(0, filename.indexOf("_")); FDroidApp.selectedApps.add(packageName); } } + FDroidApp.selectedApps = selectedApps; } }