Originally reported by Heinz Kabutz. The minimized example follows. import java.util.Collection; import java.util.concurrent.*; public class LTQ { public static void main(String... args) throws ExecutionException, InterruptedException { final int REPEATS = 10_000_000; Collection<String> msgs = new LinkedTransferQueue<>(); ExecutorService pool = Executors.newCachedThreadPool(); Future<?> f1 = pool.submit(() -> { for (int i = 0; i < REPEATS; i++) { msgs.stream().forEach(System.out::println); } }); Future<?> f2 = pool.submit(() -> { String alert = "msg"; for (int i = 0; i < REPEATS; i++) { msgs.add(alert); msgs.remove(alert); } }); pool.shutdown(); f1.get(); f2.get(); } } $ ~/trunks/jdk9-dev/build/linux-x86_64-normal-server-release/jdk/bin/java LTQ class java.util.concurrent.LinkedTransferQueue$Node Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ClassCastException: java.util.concurrent.LinkedTransferQueue$Node cannot be cast to java.lang.String at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at LTQ.main(LTQ.java:23) Caused by: java.lang.ClassCastException: java.util.concurrent.LinkedTransferQueue$Node cannot be cast to java.lang.String at java.util.concurrent.LinkedTransferQueue$LTQSpliterator.forEachRemaining(LinkedTransferQueue.java:987) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:579) at LTQ.lambda$main$0(LTQ.java:12) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:265) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Reproduces on 8u40, 8u45, latest jdk9-dev. Does not reproduce with either JDK and bootclasspath-ed JSR166. Bisection shows this is the first commit that does not fail with JSR166: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/LinkedTransferQueue.java?r1=1.70&r2=1.71
|