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

Martin Buchholz martinrb at google.com
Mon Dec 1 16:04:08 EST 2014


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:

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


More information about the Concurrency-interest mailing list