-
Bug
-
Resolution: Fixed
-
P3
-
7
-
None
-
b70
-
generic
-
generic
Martin Buchholz reports:
The following test program should never throw,
but it quickly throws NullPointerException.
import java.util.*;
import java.util.concurrent.*;
public class LBQRace {
static void checkNotContainsNull(Iterable it) {
for (Object x : it)
if (x == null)
throw new NullPointerException();
}
public static void main(String[] args) throws Throwable {
final BlockingQueue q = new LinkedBlockingQueue();
new Thread() { public void run() {
for (;;) {
q.offer(1);
}}}.start();
new Thread() { public void run() {
for (;;) {
List list = new ArrayList();
q.drainTo(list);
checkNotContainsNull(list);
}}}.start();
new Thread() { public void run() {
for (;;) {
checkNotContainsNull(q);
}}}.start();
}
}
The following test program should never throw,
but it quickly throws NullPointerException.
import java.util.*;
import java.util.concurrent.*;
public class LBQRace {
static void checkNotContainsNull(Iterable it) {
for (Object x : it)
if (x == null)
throw new NullPointerException();
}
public static void main(String[] args) throws Throwable {
final BlockingQueue q = new LinkedBlockingQueue();
new Thread() { public void run() {
for (;;) {
q.offer(1);
}}}.start();
new Thread() { public void run() {
for (;;) {
List list = new ArrayList();
q.drainTo(list);
checkNotContainsNull(list);
}}}.start();
new Thread() { public void run() {
for (;;) {
checkNotContainsNull(q);
}}}.start();
}
}
- relates to
-
JDK-6871697 LinkedBlockingQueue Iterator/remove/poll race
-
- Resolved
-