harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r936696 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/net/URLConnection.java test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
Date Thu, 22 Apr 2010 09:41:32 GMT
Author: zhoukevin
Date: Thu Apr 22 09:41:32 2010
New Revision: 936696

URL: http://svn.apache.org/viewvc?rev=936696&view=rev
Log:
Resolve an unexpected StringIndexOutOfBoundsException from java.net.URLConnection.guessContentTypeFromStream(IS)
when there is no data from the input stream to determine the content-type.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLConnection.java
    harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLConnection.java?rev=936696&r1=936695&r2=936696&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLConnection.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLConnection.java
Thu Apr 22 09:41:32 2010
@@ -681,6 +681,12 @@ public abstract class URLConnection {
         int length = is.read(bytes);
         is.reset();
 
+        // If there is no data from the input stream, can not determine
+        // content-type
+        if (length == -1) {
+            return null;
+        }
+
         // Check for Unicode BOM encoding indicators
         String encoding = "ASCII";
         int start = 0;

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java?rev=936696&r1=936695&r2=936696&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLConnectionTest.java
Thu Apr 22 09:41:32 2010
@@ -1100,6 +1100,10 @@ public class URLConnectionTest extends j
             assertEquals(expected[i], URLConnection
                     .guessContentTypeFromStream(is));
         }
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
+        assertNull(URLConnection.guessContentTypeFromStream(bais));
+        bais.close();
     }
 
     /**



Mime
View raw message