On Wed, 6 Jan 2021 08:24:04 GMT, K Suman Rajkumaar
<[email protected]> wrote:
>> test/jdk/javax/swing/JMenuItem/8031573/bug8031573.java line 68:
>>
>>> 66:
>>> 67: if (!latch.await(5, TimeUnit.MINUTES)) {
>>> 68: frame.dispose();
>>
>> The `dispose()` method should be called on EDT.
>
> If I remove the frame.dispose(), the frame doesn't gets disposed even after
> timeout.
You're right, in my previous comment I forgot about timeout.
Yet it should still be called on EDT.
However, to clean up the code a bit, I propose calling `dispose()` in finally
block. Thus there'll be only one place where frame is disposed of instead of
being scattered in multiple event handlers:
try {
// Create GUI
// Check conditions and throw exceptions on failure
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
}
}
In this case, frame will be accessed from one thread only, EDT, and does not
need to be volatile.
Since the frame is always disposed of, other calls to `frame.dispose()` can be
removed.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1878