changeset 16625:851010579420

8158651: ConcurrentModification exceptions in httpclient Reviewed-by: rriggs
author michaelm
date Fri, 03 Jun 2016 16:28:53 +0100
parents 2043de31d0a3
children 2b1e6bb88427
files src/java.httpclient/share/classes/java/net/http/Http2Connection.java src/java.httpclient/share/classes/java/net/http/Stream.java
diffstat 2 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.httpclient/share/classes/java/net/http/Http2Connection.java	Fri Jun 03 13:45:30 2016 +0100
+++ b/src/java.httpclient/share/classes/java/net/http/Http2Connection.java	Fri Jun 03 16:28:53 2016 +0100
@@ -367,7 +367,7 @@
         Log.logError(t);
         closed = true;
         client2.deleteConnection(this);
-        Collection<Stream> c = streams.values();
+        List<Stream> c = new LinkedList<>(streams.values());
         for (Stream s : c) {
             s.cancelImpl(t);
         }
--- a/src/java.httpclient/share/classes/java/net/http/Stream.java	Fri Jun 03 13:45:30 2016 +0100
+++ b/src/java.httpclient/share/classes/java/net/http/Stream.java	Fri Jun 03 16:28:53 2016 +0100
@@ -30,6 +30,7 @@
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CompletionException;
@@ -537,7 +538,7 @@
      * getResponseAsync()
      */
 
-    final List<CompletableFuture<HttpResponseImpl>> response_cfs = new LinkedList<>();
+    final List<CompletableFuture<HttpResponseImpl>> response_cfs = new ArrayList<>(5);
 
     @Override
     CompletableFuture<HttpResponseImpl> getResponseAsync(Void v) {
@@ -565,17 +566,16 @@
     void completeResponse(HttpResponse r) {
         HttpResponseImpl resp = (HttpResponseImpl)r;
         synchronized (response_cfs) {
-            for (CompletableFuture<HttpResponseImpl> cf : response_cfs) {
+            int cfs_len = response_cfs.size();
+            for (int i=0; i<cfs_len; i++) {
+                CompletableFuture<HttpResponseImpl> cf = response_cfs.get(i);
                 if (!cf.isDone()) {
                     cf.complete(resp);
                     response_cfs.remove(cf);
-                    //responseHeaders = new HttpHeadersImpl(); // for any following header blocks
                     return;
-                } else
-                    System.err.println("Stream: " + this + " ALREADY DONE");
+                }
             }
             response_cfs.add(CompletableFuture.completedFuture(resp));
-            //responseHeaders = new HttpHeadersImpl(); // for any following header blocks
         }
     }