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.
This commit is contained in:
parent
af3a6369cc
commit
4f7f87be0a
@ -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<String>();
|
||||
HashSet<String> selectedApps = new HashSet<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user