Skip to content

Commit 004c5c2

Browse files
committed
UIService: Do *not* conflate the 'initialized' and 'disposed' flags
Earlier, this developer tried to be smart (failing) and reuse the 'initialized' flag to indicate whether to show the user interface or not. However, that flag did not indicate whether the initialize() method was run yet, but whether the service's lazy initialization was already performed or not. Let's just have a separate flag to indicate whether the context was disposed or not. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3087de7 commit 004c5c2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/scijava/ui/DefaultUIService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public final class DefaultUIService extends AbstractService implements
134134
/** Whether lazy initialization is complete. */
135135
private boolean initialized;
136136

137+
/** Whether the service was disposed */
138+
private boolean disposed;
139+
137140
/** The default user interface to use, if one is not explicitly specified. */
138141
private UserInterface defaultUI;
139142

@@ -154,7 +157,7 @@ public void addUI(final String name, final UserInterface ui) {
154157

155158
@Override
156159
public void showUI() {
157-
if (!initialized) return;
160+
if (disposed) return;
158161
final UserInterface ui = getDefaultUI();
159162
if (ui == null) {
160163
throw new IllegalStateException("No UIs available.");
@@ -358,7 +361,7 @@ public synchronized void dispose() {
358361
for (int i = uis.size() - 1; i >= 0; i--) {
359362
uis.get(i).dispose();
360363
}
361-
initialized = false;
364+
disposed = true;
362365
}
363366

364367
// -- Event handlers --

0 commit comments

Comments
 (0)