From e719bbd88c5413177875d475b53bb26d93bbb65f Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 26 Aug 2012 10:25:11 -0500 Subject: [PATCH] Fix Future task waiting logic. Fixes BUKKIT-2408 Previously, the timeout would erroneously get converted to milliseconds twice. The second conversion was removed. Spurious wakeups were not handled properly, and would instead throw a TimeoutException even if the waited time was not reached.. By: Wesley Wolfe --- .../java/org/bukkit/craftbukkit/scheduler/CraftFuture.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java index de96ec9b7..fee49c92b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftFuture.java @@ -48,14 +48,19 @@ class CraftFuture extends CraftTask implements Future { public synchronized T get(long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { timeout = unit.toMillis(timeout); long period = this.getPeriod(); + long timestamp = timeout > 0 ? System.currentTimeMillis() : 0l; while (true) { if (period == -1l || period == -3l) { - this.wait(unit.toMillis(timeout)); + this.wait(timeout); period = this.getPeriod(); if (period == -1l || period == -3l) { if (timeout == 0l) { continue; } + timeout += timestamp - (timestamp = System.currentTimeMillis()); + if (timeout > 0) { + continue; + } throw new TimeoutException(); } }