diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-05-05 18:21:07 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-05 18:21:07 -0700 |
commit | 4f305bfb4fc16b7f80c323f44987f9a2315e2eb4 (patch) | |
tree | e248d3275f3b322a0cbdc7232c960dac11670517 | |
parent | a47f80079c7147f6edc83ae812435326bd82dd40 (diff) | |
parent | 5e8b5a55eda914b67c62b4e77152922d5c77eb68 (diff) | |
download | libcore-4f305bfb4fc16b7f80c323f44987f9a2315e2eb4.zip libcore-4f305bfb4fc16b7f80c323f44987f9a2315e2eb4.tar.gz libcore-4f305bfb4fc16b7f80c323f44987f9a2315e2eb4.tar.bz2 |
Merge "Don't read from the delegate stream after we close it." into honeycomb-mr2
3 files changed, 22 insertions, 3 deletions
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java index c5eec13..84cf32f 100644 --- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java +++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java @@ -35,7 +35,7 @@ final class UnknownLengthHttpInputStream extends AbstractHttpInputStream { @Override public int read(byte[] buffer, int offset, int count) throws IOException { Arrays.checkOffsetAndCount(buffer.length, offset, count); checkNotClosed(); - if (in == null) { + if (in == null || inputExhausted) { return -1; } int read = in.read(buffer, offset, count); diff --git a/luni/src/test/java/libcore/java/net/URLConnectionTest.java b/luni/src/test/java/libcore/java/net/URLConnectionTest.java index 81f23f0..e24582b 100644 --- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java +++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java @@ -1903,6 +1903,25 @@ public class URLConnectionTest extends junit.framework.TestCase { assertFalse(aborted.get()); // The best behavior is ambiguous, but RI 6 doesn't abort here } + + /** + * http://code.google.com/p/android/issues/detail?id=14562 + */ + public void testReadAfterLastByte() throws Exception { + server.enqueue(new MockResponse() + .setBody("ABC") + .clearHeaders() + .addHeader("Connection: close") + .setSocketPolicy(SocketPolicy.DISCONNECT_AT_END)); + server.play(); + + HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection(); + InputStream in = connection.getInputStream(); + assertEquals("ABC", readAscii(in, 3)); + assertEquals(-1, in.read()); + assertEquals(-1, in.read()); // throws IOException in Gingerbread + } + /** * Encodes the response body using GZIP and adds the corresponding header. */ diff --git a/support/src/test/java/tests/http/MockWebServer.java b/support/src/test/java/tests/http/MockWebServer.java index 35729ed..ded29bd 100644 --- a/support/src/test/java/tests/http/MockWebServer.java +++ b/support/src/test/java/tests/http/MockWebServer.java @@ -33,11 +33,11 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingDeque; @@ -63,7 +63,7 @@ public final class MockWebServer { private final BlockingQueue<MockResponse> responseQueue = new LinkedBlockingDeque<MockResponse>(); private final Set<Socket> openClientSockets - = Collections.synchronizedSet(new HashSet<Socket>()); + = Collections.newSetFromMap(new ConcurrentHashMap<Socket, Boolean>()); private boolean singleResponse; private final AtomicInteger requestCount = new AtomicInteger(); private int bodyLimit = Integer.MAX_VALUE; |