diff --git a/classlib/src/main/java/org/teavm/classlib/java/net/TURL.java b/classlib/src/main/java/org/teavm/classlib/java/net/TURL.java index 0aba53fa2..fe3086bd7 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/net/TURL.java +++ b/classlib/src/main/java/org/teavm/classlib/java/net/TURL.java @@ -72,7 +72,7 @@ public final class TURL implements Serializable { throw new TMalformedURLException(e.toString()); } int startIPv6Addr = spec.indexOf('['); - if (index >= 0) { + if (index > 0) { if (startIPv6Addr == -1 || index < startIPv6Addr) { protocol = spec.substring(0, index); // According to RFC 2396 scheme part should match diff --git a/tests/src/test/java/org/teavm/classlib/java/net/URLTest.java b/tests/src/test/java/org/teavm/classlib/java/net/URLTest.java index 1768a5da8..5a40be35d 100644 --- a/tests/src/test/java/org/teavm/classlib/java/net/URLTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/net/URLTest.java @@ -228,6 +228,15 @@ public class URLTest { } catch (MalformedURLException e) { fail("Unexpected exception (jar protocol, relative path)" + e); } + + // no protocol + caught = false; + try { + u = new URL(":"); + } catch (MalformedURLException e) { + caught = true; + } + assertTrue("7 Failed to throw MalformedURLException", caught); } @Test