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

@@ -86,8 +86,9 @@ public final class ScheduledTask {
*/
@Nullable
public Instant nextExecution() {
if (this.future != null && !this.future.isCancelled()) {
long delay = this.future.getDelay(TimeUnit.MILLISECONDS);
ScheduledFuture<?> future = this.future;
if (future != null && !future.isCancelled()) {
long delay = future.getDelay(TimeUnit.MILLISECONDS);
if (delay > 0) {
return Instant.now().plusMillis(delay);
}