Skip to content

Commit 39e17fb

Browse files
committed
Use synchronized double lock in DefaultMenuService
The root menu creation was not protected via a synchronized double lock, which could have created problems if initializion was attempted by multiple threads.
1 parent 54200aa commit 39e17fb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/org/scijava/menu/DefaultMenuService.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,19 @@ private synchronized void addModules(final Collection<ModuleInfo> items) {
173173
*/
174174
private HashMap<String, ShadowMenu> rootMenus() {
175175
if (rootMenus == null) {
176-
rootMenus = new HashMap<String, ShadowMenu>();
177-
178-
final List<ModuleInfo> allModules = moduleService.getModules();
179-
addModules(allModules);
176+
initRootMenus();
180177
}
181178
return rootMenus;
182179
}
183180

181+
/** Initializes {@link #rootMenus}. */
182+
private synchronized void initRootMenus() {
183+
if (rootMenus != null) return;
184+
final HashMap<String, ShadowMenu> map = new HashMap<String, ShadowMenu>();
185+
186+
final List<ModuleInfo> allModules = moduleService.getModules();
187+
addModules(allModules);
188+
rootMenus = map;
189+
}
190+
184191
}

0 commit comments

Comments
 (0)