RFR: 8081474: SwingWorker calls 'done' before the 'doInBackground' is finished [v8]

Alexey Ivanov aivanov at openjdk.org
Thu Feb 2 11:52:32 UTC 2023


On Tue, 31 Jan 2023 15:34:44 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> SwingWorker done() method [spec ](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L452) says "Executed on the Event Dispatch Thread after the doInBackground method is finished"
>> but there's no mechanism in place to honor that claim.
>> The [spec](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L289)
>> also says the state should be DONE after doInBackground() returns which is also not done.
>> 
>> Modified the code to honour the specification.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Test update

Changes requested by aivanov (Reviewer).

test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java line 36:

> 34: public class TestDoneBeforeDoInBackground {
> 35: 
> 36:     static boolean doInBackground = false;

Suggestion:

    private static boolean doInBackground = false;

Let's make it private too.

test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java line 38:

> 36:     static boolean doInBackground = false;
> 37:     private static final int WAIT_TIME = 200;
> 38:     private static final long CLEANUP_TIME = 3000;

Suggestion:

    private static final long CLEANUP_TIME = 1000;

1 second is enough for automatic test.

test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java line 89:

> 87:             throw new RuntimeException("done didn't complete in time");
> 88:         }
> 89:         System.out.println("doInBackground " + doInBackground);

Suggestion:

        System.out.println("doInBackground = " + doInBackground);

Maybe add getState() too?

-------------

PR: https://git.openjdk.org/jdk/pull/11940



More information about the client-libs-dev mailing list