Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

libcore: Commit

libcore


Commit MetaInfo

Revisionf241d462634527692b7d99335cdc8c11883ac966 (tree)
Time2011-03-30 03:23:46
AuthorJesse Wilson <jessewilson@goog...>
CommiterJesse Wilson

Log Message

Don't read from the delegate stream after we close it.

Change-Id: I9a018ca88373d5f317335e35fc6ca43c5473490e
http://b/4188137

Change Summary

Incremental Difference

--- 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
@@ -34,7 +34,7 @@ final class UnknownLengthHttpInputStream extends AbstractHttpInputStream {
3434 @Override public int read(byte[] buffer, int offset, int count) throws IOException {
3535 checkBounds(buffer, offset, count);
3636 checkNotClosed();
37- if (in == null) {
37+ if (in == null || inputExhausted) {
3838 return -1;
3939 }
4040 int read = in.read(buffer, offset, count);
--- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java
+++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
@@ -1501,6 +1501,24 @@ public class URLConnectionTest extends junit.framework.TestCase {
15011501 }
15021502
15031503 /**
1504+ * http://code.google.com/p/android/issues/detail?id=14562
1505+ */
1506+ public void testReadAfterLastByte() throws Exception {
1507+ server.enqueue(new MockResponse()
1508+ .setBody("ABC")
1509+ .clearHeaders()
1510+ .addHeader("Connection: close")
1511+ .setDisconnectAtEnd(true));
1512+ server.play();
1513+
1514+ HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
1515+ InputStream in = connection.getInputStream();
1516+ assertEquals("ABC", readAscii(in, 3));
1517+ assertEquals(-1, in.read());
1518+ assertEquals(-1, in.read()); // throws IOException in Gingerbread
1519+ }
1520+
1521+ /**
15041522 * Encodes the response body using GZIP and adds the corresponding header.
15051523 */
15061524 public byte[] gzip(byte[] bytes) throws IOException {
--- a/support/src/test/java/tests/http/MockWebServer.java
+++ b/support/src/test/java/tests/http/MockWebServer.java
@@ -32,12 +32,12 @@ import java.net.URL;
3232 import java.net.UnknownHostException;
3333 import java.util.ArrayList;
3434 import java.util.Collections;
35-import java.util.HashSet;
3635 import java.util.Iterator;
3736 import java.util.List;
3837 import java.util.Set;
3938 import java.util.concurrent.BlockingQueue;
4039 import java.util.concurrent.Callable;
40+import java.util.concurrent.ConcurrentHashMap;
4141 import java.util.concurrent.ExecutorService;
4242 import java.util.concurrent.Executors;
4343 import java.util.concurrent.LinkedBlockingDeque;
@@ -59,7 +59,7 @@ public final class MockWebServer {
5959 private final BlockingQueue<MockResponse> responseQueue
6060 = new LinkedBlockingDeque<MockResponse>();
6161 private final Set<Socket> openClientSockets
62- = Collections.synchronizedSet(new HashSet<Socket>());
62+ = Collections.newSetFromMap(new ConcurrentHashMap<Socket, Boolean>());
6363 private boolean singleResponse;
6464 private final AtomicInteger requestCount = new AtomicInteger();
6565 private int bodyLimit = Integer.MAX_VALUE;
Show on old repository browser