Index: src/test/java/tests/api/java/net/URLTest.java =================================================================== --- src/test/java/tests/api/java/net/URLTest.java (revision 492381) +++ src/test/java/tests/api/java/net/URLTest.java (working copy) @@ -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); + } } Index: src/main/java/java/net/URLStreamHandler.java =================================================================== --- src/main/java/java/net/URLStreamHandler.java (revision 492381) +++ src/main/java/java/net/URLStreamHandler.java (working copy) @@ -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 = "";