Defensive access to volatile ScheduledFuture field

Includes defensive test arrangement for isInThePast() with at least 1 ms having passed.

See gh-24560
This commit is contained in:
Juergen Hoeller
2024-06-12 13:01:58 +02:00
parent 099d016857
commit 7a7f34f4ad
2 changed files with 18 additions and 3 deletions

View File

@@ -24,7 +24,9 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Tests for {@link Task}.
*
* @author Brian Clozel
* @since 6.2
*/
class TaskTests {
@@ -77,20 +79,32 @@ class TaskTests {
@Override
public void run() {
try {
Thread.sleep(1);
}
catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
this.hasRun = true;
}
}
static class FailingTestRunnable implements Runnable {
boolean hasRun;
@Override
public void run() {
try {
Thread.sleep(1);
}
catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
this.hasRun = true;
throw new IllegalStateException("test exception");
}
}
}