Skip to content

Commit 4a2afb4

Browse files
8295962: Reference to State in Task.java is ambiguous when building with JDK 19
Reviewed-by: angorya, arapte
1 parent b3eec1d commit 4a2afb4

5 files changed

Lines changed: 29 additions & 28 deletions

File tree

modules/javafx.graphics/src/main/java/javafx/concurrent/Task.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -690,14 +690,14 @@ private Task(final TaskCallable<V> callableAdapter) {
690690
*/
691691
protected abstract V call() throws Exception;
692692

693-
private ObjectProperty<State> state = new SimpleObjectProperty<>(this, "state", State.READY);
694-
final void setState(State value) { // package access for the Service
693+
private ObjectProperty<Worker.State> state = new SimpleObjectProperty<>(this, "state", Worker.State.READY);
694+
final void setState(Worker.State value) { // package access for the Service
695695
checkThread();
696-
final State s = getState();
697-
if (s != State.CANCELLED) {
696+
final Worker.State s = getState();
697+
if (s != Worker.State.CANCELLED) {
698698
this.state.set(value);
699699
// Make sure the running flag is set
700-
setRunning(value == State.SCHEDULED || value == State.RUNNING);
700+
setRunning(value == Worker.State.SCHEDULED || value == Worker.State.RUNNING);
701701

702702
// Invoke the event handlers, and then call the protected methods.
703703
switch (state.get()) {
@@ -729,8 +729,8 @@ final void setState(State value) { // package access for the Service
729729
}
730730
}
731731
}
732-
@Override public final State getState() { checkThread(); return state.get(); }
733-
@Override public final ReadOnlyObjectProperty<State> stateProperty() { checkThread(); return state; }
732+
@Override public final Worker.State getState() { checkThread(); return state.get(); }
733+
@Override public final ReadOnlyObjectProperty<Worker.State> stateProperty() { checkThread(); return state; }
734734

735735
/**
736736
* The onSchedule event handler is called whenever the Task state
@@ -1025,9 +1025,9 @@ protected void failed() { }
10251025
// state flag will not be readable immediately after this call. However,
10261026
// that would be the case anyway since these properties are not thread-safe.
10271027
if (isFxApplicationThread()) {
1028-
setState(State.CANCELLED);
1028+
setState(Worker.State.CANCELLED);
10291029
} else {
1030-
runLater(() -> setState(State.CANCELLED));
1030+
runLater(() -> setState(Worker.State.CANCELLED));
10311031
}
10321032
}
10331033
// return the flag
@@ -1418,8 +1418,8 @@ private TaskCallable() { }
14181418
// in all cases so that developer code can be consistent.
14191419
task.started = true;
14201420
task.runLater(() -> {
1421-
task.setState(State.SCHEDULED);
1422-
task.setState(State.RUNNING);
1421+
task.setState(Worker.State.SCHEDULED);
1422+
task.setState(Worker.State.RUNNING);
14231423
});
14241424
// Go ahead and delegate to the wrapped callable
14251425
try {
@@ -1434,7 +1434,7 @@ private TaskCallable() { }
14341434
// can assume if the result is set, it has
14351435
// succeeded.
14361436
task.updateValue(result);
1437-
task.setState(State.SUCCEEDED);
1437+
task.setState(Worker.State.SUCCEEDED);
14381438
});
14391439
return result;
14401440
} else {
@@ -1453,7 +1453,7 @@ private TaskCallable() { }
14531453
// in that circumstance.
14541454
task.runLater(() -> {
14551455
task._setException(th);
1456-
task.setState(State.FAILED);
1456+
task.setState(Worker.State.FAILED);
14571457
});
14581458
// Some error occurred during the call (it might be
14591459
// an exception (either runtime or checked), or it might

modules/javafx.graphics/src/shims/java/javafx/concurrent/TaskShim.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,7 @@ public void runLater(Runnable r) {
4949
super.runLater(r);
5050
}
5151

52-
public void shim_setState(State value) {
52+
public void shim_setState(Worker.State value) {
5353
super.setState(value);
5454
}
5555

modules/javafx.graphics/src/test/java/test/javafx/concurrent/AbstractTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,8 @@
2626
package test.javafx.concurrent;
2727

2828
import java.util.concurrent.Semaphore;
29-
import javafx.concurrent.Task;
3029
import javafx.concurrent.TaskShim;
30+
import javafx.concurrent.Worker;
3131

3232
/**
3333
* For testing purposes, we use this subclass of Task that will fake out the
@@ -59,7 +59,7 @@ public abstract class AbstractTask extends TaskShim<String> {
5959

6060
// Simulates scheduling the concurrent for execution
6161
public void simulateSchedule() {
62-
shim_setState(State.SCHEDULED);
62+
shim_setState(Worker.State.SCHEDULED);
6363
}
6464

6565
// For most tests, we want to pretend that we are on the FX app thread, always.

modules/javafx.graphics/src/test/java/test/javafx/concurrent/TaskCancelTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package test.javafx.concurrent;
2727

2828
import javafx.concurrent.Task;
29+
import javafx.concurrent.Worker;
2930
import test.javafx.concurrent.mocks.EpicFailTask;
3031
import test.javafx.concurrent.mocks.InfiniteTask;
3132
import test.javafx.concurrent.mocks.RunAwayTask;
@@ -57,7 +58,7 @@ public class TaskCancelTest {
5758
*/
5859
@Test public void cancellingA_READY_TaskShouldChangeStateTo_CANCELLED() {
5960
assertTrue(task.cancel());
60-
assertEquals(Task.State.CANCELLED, task.getState());
61+
assertEquals(Worker.State.CANCELLED, task.getState());
6162
assertTrue(task.isDone());
6263
}
6364

@@ -69,7 +70,7 @@ public class TaskCancelTest {
6970
@Test public void cancellingA_SCHEDULED_TaskShouldChangeStateTo_CANCELLED() {
7071
task.simulateSchedule();
7172
assertTrue(task.cancel());
72-
assertEquals(Task.State.CANCELLED, task.getState());
73+
assertEquals(Worker.State.CANCELLED, task.getState());
7374
assertTrue(task.isDone());
7475
}
7576

@@ -90,7 +91,7 @@ public class TaskCancelTest {
9091
assertTrue(task.cancel());
9192
th.join();
9293

93-
assertEquals(Task.State.CANCELLED, task.getState());
94+
assertEquals(Worker.State.CANCELLED, task.getState());
9495
// TODO why is this commented out?
9596
// assertNull(task.getException());
9697
assertNull(task.getValue());
@@ -105,7 +106,7 @@ public class TaskCancelTest {
105106
Task t = new SimpleTask();
106107
t.run();
107108
assertFalse(t.cancel());
108-
assertEquals(Task.State.SUCCEEDED, t.getState());
109+
assertEquals(Worker.State.SUCCEEDED, t.getState());
109110
assertTrue(t.isDone());
110111
}
111112

@@ -117,7 +118,7 @@ public class TaskCancelTest {
117118
Task t = new EpicFailTask();
118119
t.run();
119120
assertFalse(t.cancel());
120-
assertEquals(Task.State.FAILED, t.getState());
121+
assertEquals(Worker.State.FAILED, t.getState());
121122
assertTrue(t.isDone());
122123
}
123124

@@ -136,7 +137,7 @@ protected void loop(int count) throws Exception {
136137
runAway.stopLooping.set(true);
137138
th.join();
138139

139-
assertEquals(Task.State.CANCELLED, runAway.getState());
140+
assertEquals(Worker.State.CANCELLED, runAway.getState());
140141
// TODO why is this commented out?
141142
// assertNull(task.getException());
142143
assertNull(runAway.getValue());

modules/javafx.graphics/src/test/java/test/javafx/concurrent/TaskSimpleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@ public class TaskSimpleTest {
6565
***********************************************************************/
6666

6767
@Test public void stateShouldBe_READY_ByDefault() {
68-
assertEquals(Task.State.READY, task.getState());
68+
assertEquals(Worker.State.READY, task.getState());
6969
}
7070

7171
@Test public void workDoneShouldBe_Indeterminate_ByDefault() {

0 commit comments

Comments
 (0)