On Tue, 9 Jun 2026 13:35:34 GMT, Alexey Ivanov <[email protected]> wrote:
>> Interesting… >> >> According to the comment in the test, >> https://github.com/openjdk/jdk/blob/b6fb712b6fcb1095c162ba15bf519045a8c451ae/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java#L94-L98 >> >> by the time `doInBackground` starts the `START` notification will have been >> delivered. Thus `workerStarted.await` still covers this case. > > What would be the behaviour if `cancel` is called before `doInBackground` > starts? Should we create a test for it, if at all possible? Alexander is *right*. The comment in the code that I quoted above states the expected order of the events only. https://github.com/openjdk/jdk/blob/d46298d681f78d8f16ee4ed8031520dcd76d3c4c/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L302-L308 The state of the `SwingWorker` object changes to `STARTED` *before* the `doInBackground` method is called, but the notification is posted to EDT asynchronously. Therefore, the test may still fail if `worker.cancel(true)` is executed before`PropertyChangeEvent` for the `START` state reaches EDT. The `doInBackgroundStarted` flag is set to `true` after `Thread.sleep(WAIT_TIME)` is interrupted. Thus, the condition https://github.com/openjdk/jdk/blob/b6fb712b6fcb1095c162ba15bf519045a8c451ae/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java#L97-L98 will evaluate to `true`, and the test will fail. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/31348#discussion_r3397536872
