Hi all, I was not sure if my runs of SequencedEventTest test were triggering the problematic execution flow, because this issue should manifest even after JDK-8152974 [1] fix. After a few tries I attached a debugger. Attaching a debugger obviously interferred with robot steps on the test but, anyways, handled it and reproduced the problem.
I had a quick look and this is my hypothesis for JDK-8204142 [2] issue: Let's say we have EDT0 (EventQueue0, AppContext0) and EDT1 (EventQueue1, AppContext1). Both threads are dispatching events from their respective EventQueue queues. In particular, dispatching SequencedEvent events. We also have SequencedEvent.list list, in which SequencedEvent events from both AppContext0 and AppContext1 are interleaved. These SequencedEvent events will be dispatched by both EDT0 and EDT1 (EDT0 dispatching AppContext0 events from EventQueue0 and EDT1 dispatching AppContext1 events from EventQueue1). Now, we may have the following sequence of events in the SequencedEvent.list queue: EV0-AppContext0, EV0-AppContext1, EV1-AppContext1, EV1-AppContext0. Events, though, may come to EventQueue queues out of order (I.e: EventQueue1 may have EV1-AppContext1 first and EV0-AppContext1 then, while EventQueue0 may have EV0-AppContext0 first and EV1-AppContext0 then). In the previous scenario, EDT1 will try to dispatch EV1-AppContext1 first. However, it notices that it is not the first event in the SequencedEvent.list queue. After JDK-8152974 [1] fix, EDT1 will try to dispatch other SequencedEvents from his EventQueue queue. So it goes straight to EV0-AppContext1, which is the next one in EventQueue1. It notices that this is not the first event in SequencedEvent.list queue and tries to do the same. However, no more SequencedEvents are available for him to dispatch (no more SequencedEvents in EventQueue1). It will then block indefinitely waiting for SequencedEvents to come to EventQueue1. Now it's time for EDT0. EDT0 will successfully dispatch EV0-AppContext0 and then try to dispatch EV1-AppContext0. When trying to dispatch the latter, it will notice that it is not the first one in SequencedEvent.list queue and blocks the same way EDT1 did before. Now we have both EDT0 and EDT1 blocked waiting for SequencedEvent events to come to their respective EventQueue queues. EDT1 should have woken up and proceeded dispatching EV0-AppContext1. The underlying problem is that SequencedEvent.dispatch function is not prepared for SequencedEvent.list list to have events from different EventQueue queues, dispatched by different EDTs. The assumption that if the event is not the first one on SequencedEvent.list list we will successfully be able to dispatch an event from the EventQueue and unblock the sequence is wrong. We may wait for this event indefinitely and, at some point, we will be the ones blocking the whole thing because our event now is the first one. Please note here that the wake-up scheme in SequencedEvent.dispose function fails because it's sending SentEvent events and the waiting thread (after JDK-8152974 [1]) is filtering SequencedEvent events. Kind regards, Martin.- -- [1] - https://bugs.openjdk.java.net/browse/JDK-8152974 [2] - https://bugs.openjdk.java.net/browse/JDK-8204142