harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r954849 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/net/URLStreamHandler.java test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Date Tue, 15 Jun 2010 12:14:54 GMT
Author: tellison
Date: Tue Jun 15 12:14:54 2010
New Revision: 954849

URL: http://svn.apache.org/viewvc?rev=954849&view=rev
Log:
Apply (slightly reformatted) patch for HARMONY-6499 ([classlib][luni] URLStreamHandler.parseURL
throws different exception to RI in some cases)

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

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java?rev=954849&r1=954848&r2=954849&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/net/URLStreamHandler.java
Tue Jun 15 12:14:54 2010
@@ -85,22 +85,19 @@ public abstract class URLStreamHandler {
      * @see URL
      */
     protected void parseURL(URL u, String str, int start, int end) {
-        // For compatibility, refer to Harmony-2941
-        if (str.startsWith("//", start) //$NON-NLS-1$
-                && str.indexOf('/', start + 2) == -1
-                && end <= Integer.MIN_VALUE + 1) {
-            throw new StringIndexOutOfBoundsException(end - 2 - start);
-        }
-        if (end < start) {
+        if (end < start || end < 0) {
+            // Checks to ensure string index exception ahead of
+            // security exception for compatibility.
+            if (end <= Integer.MIN_VALUE + 1 && (start >= str.length() || start
< 0)
+                    || str.startsWith("//", start) && str.indexOf('/', start + 2)
== -1) { //$NON-NLS-1$
+                throw new StringIndexOutOfBoundsException(end);
+            }
             if (this != u.strmHandler) {
                 throw new SecurityException();
             }
             return;
         }
-        String parseString = ""; //$NON-NLS-1$
-        if (start < end) {
-            parseString = str.substring(start, end);
-        }
+        String parseString = str.substring(start, end);
         end -= start;
         int fileIdx = 0;
 

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.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/URLTest.java?rev=954849&r1=954848&r2=954849&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URLTest.java
Tue Jun 15 12:14:54 2010
@@ -1382,6 +1382,49 @@ public class URLTest extends TestCase {
         } catch (SecurityException e) {
             // expected;
         }
+        
+        // Regression tests for HARMONY-6499
+        try {
+            handler.parse(url, "any", 10, Integer.MIN_VALUE);
+            fail("Should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        
+        try {
+            handler.parse(url, "any", 10, Integer.MIN_VALUE+1);
+            fail("Should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        
+        try {
+            handler.parse(url, "any", Integer.MIN_VALUE, Integer.MIN_VALUE);
+            fail("Should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        
+        try {
+            handler.parse(url, "any", Integer.MIN_VALUE, 2);
+            fail("Should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        
+        try {
+            handler.parse(url, "any", -1, 2);
+            fail("Should throw StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        
+        try {
+            handler.parse(url, "any", -1, -1);
+            fail("Should throw SecurityException");
+        } catch (SecurityException e) {
+            // expected;
+        }
     }
 
     /**



Mime
View raw message