harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r492972 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLStreamHandler.java test/java/tests/api/java/net/URLTest.java
Date Fri, 05 Jan 2007 10:43:17 GMT
Author: tellison
Date: Fri Jan  5 02:43:16 2007
New Revision: 492972

URL: http://svn.apache.org/viewvc?view=rev&rev=492972
Log:
Apply patch HARMONY-2941 ([classlib][luni]No exception was thrown when parseURL with limit
= Integer.MIN_VALUE)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java?view=diff&rev=492972&r1=492971&r2=492972
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLStreamHandler.java
Fri Jan  5 02:43:16 2007
@@ -85,7 +85,15 @@
 	 * @see URL
 	 */
 	protected void parseURL(URL u, String str, int start, int end) {
-		if (end < start) {
+        // For compatibility, refer to Harmony-2941
+        if (str.startsWith("//", start) && str.indexOf('/', start + 2) == -1
+                && end <= Integer.MIN_VALUE + 1) {
+            throw new StringIndexOutOfBoundsException(end - 2 - start);
+        }
+        if (end < start) {
+            if (this != u.strmHandler) {
+                throw new SecurityException();
+            }
             return;
         }
 		String parseString = "";

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java?view=diff&rev=492972&r1=492971&r2=492972
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLTest.java
Fri Jan  5 02:43:16 2007
@@ -35,7 +35,6 @@
 import java.security.Permission;
 import java.util.ArrayList;
 import java.util.List;
-
 import tests.support.Support_Configuration;
 import tests.support.resource.Support_Resources;
 
@@ -1322,4 +1321,53 @@
 		}
 
 	}
+    static class MyURLStreamHandler extends URLStreamHandler {
+
+        @Override
+        protected URLConnection openConnection(URL arg0) throws IOException {
+            return null;
+        }
+
+        public void parse(URL url, String spec, int start, int end) {
+            parseURL(url, spec, start, end);
+        }
+    }
+
+    static class MyURLStreamHandlerFactory implements URLStreamHandlerFactory {
+
+        public static MyURLStreamHandler handler = new MyURLStreamHandler();
+
+        public URLStreamHandler createURLStreamHandler(String arg0) {
+            handler = new MyURLStreamHandler();
+            return handler;
+        }
+
+    }
+
+    // Regression test for harmony-2941
+    public void test_URLStreamHandler_parseURL() throws MalformedURLException {
+        URL.setURLStreamHandlerFactory(new MyURLStreamHandlerFactory());
+        URL url = new URL("null://localhost");
+        MyURLStreamHandler handler = MyURLStreamHandlerFactory.handler;
+        try {
+            handler.parse(url, "//", 0, Integer.MIN_VALUE);
+            fail("Should throw SIOOBE.");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        try {
+            handler.parse(url, "1234//", 4, Integer.MIN_VALUE);
+            fail("Should throw SIOOBE.");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        try {
+            handler.parse(url, "1", -1, 0);
+            fail("Should throw SIOOBE.");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected;
+        }
+        handler.parse(url, "1", 3, 2);
+        handler.parse(url, "11", 1, Integer.MIN_VALUE);
+    }
 }



Mime
View raw message