# HG changeset patch # User dl # Date 1320927709 0 # Node ID 27f7a2f3be206418c35477e8e0f55c246a06456a # Parent 13ee761ef120fa84d5884e0a6816b513b9182132 7107516: LinkedBlockingQueue/Deque.drainTo(Collection, int) returns 'maxElements' if its value is negative Reviewed-by: chegar, mduigou, dholmes diff -r 13ee761ef120 -r 27f7a2f3be20 jdk/src/share/classes/java/util/concurrent/LinkedBlockingDeque.java --- a/jdk/src/share/classes/java/util/concurrent/LinkedBlockingDeque.java Wed Nov 09 15:51:18 2011 +0800 +++ b/jdk/src/share/classes/java/util/concurrent/LinkedBlockingDeque.java Thu Nov 10 12:21:49 2011 +0000 @@ -742,6 +742,8 @@ throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); + if (maxElements <= 0) + return 0; final ReentrantLock lock = this.lock; lock.lock(); try { diff -r 13ee761ef120 -r 27f7a2f3be20 jdk/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java --- a/jdk/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java Wed Nov 09 15:51:18 2011 +0800 +++ b/jdk/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java Thu Nov 10 12:21:49 2011 +0000 @@ -332,7 +332,7 @@ // Note: convention in all put/take/etc is to preset local var // holding count negative to indicate failure unless set. int c = -1; - Node node = new Node(e); + Node node = new Node(e); final ReentrantLock putLock = this.putLock; final AtomicInteger count = this.count; putLock.lockInterruptibly(); @@ -412,7 +412,7 @@ if (count.get() == capacity) return false; int c = -1; - Node node = new Node(e); + Node node = new Node(e); final ReentrantLock putLock = this.putLock; putLock.lock(); try { @@ -728,6 +728,8 @@ throw new NullPointerException(); if (c == this) throw new IllegalArgumentException(); + if (maxElements <= 0) + return 0; boolean signalNotFull = false; final ReentrantLock takeLock = this.takeLock; takeLock.lock();