[concurrency-interest] Condition.awaitNanos(Long.MIN_VALUE)

Doug Lea dl at cs.oswego.edu
Mon Dec 1 19:21:04 EST 2014


On 12/01/2014 04:04 PM, Martin Buchholz wrote:
> I just finished telling Charlie that it's impossible to find
> concurrency bugs in old j.u.c. code, but here I am claiming this is
> one:
> awaitNanos is at risk of underflow:

Thanks. The method is correct in not waiting, but
with extreme negative arguments (about -500 years), can return
an overflowed (not saturated) remaining time estimate.
A simple fix for AbstractQueued{Long}Synchronizer classes is
now in jsr166 CVS. Feel free to report and sync.

-Doug


>
> import java.util.concurrent.locks.*;
>
> public class NegativeInfinityWait {
>      public static void main(String[] args) throws Throwable {
>          ReentrantLock lock = new ReentrantLock();
>          Condition condition = lock.newCondition();
>          lock.lock();
>          System.out.println(condition.awaitNanos(Long.MIN_VALUE));
>      }
> }
> ==> javac -source 1.9 -Xlint:all NegativeInfinityWait.java
> ==> java -esa -ea NegativeInfinityWait
> 9223372036854686346
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



More information about the Concurrency-interest mailing list