-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8, 9
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux john 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
java.net.URI throws URISyntaxException when hostname contains underscore.
The following instruction will throw an URISyntaxException:
URI uriNotWorking = new URI("http", null,"my_site.xyz.com", 9999, "/hello/world", "myparam=ABCDE", null);
The following instruction will NOT throw an exception:
URI uriWorking = new URL("http://my_site.xyz.com:9999/hello/world?myparam=ABCDE").toUri();
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create an instance of java.net.URI such that the hostname contains an underscore:
URI uri = new URI("http", null,"my_site.xyz.com", 9999, "/hello/world", "myparam=ABCDE", null);
or
URI uri = new URI("http", null,"my_site.com", 9999, "/hello/world", "myparam=ABCDE", null);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Instance of java.net.URI pointing to the correct URL.
ACTUAL -
Thrown instance of java.net.URISyntaxException.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.net.URISyntaxException: Illegal character in hostname at index 9: http://my_site.com:9999/hello/world?myparam=ABCDE
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.parseHostname(URI.java:3387)
at java.net.URI$Parser.parseServer(URI.java:3236)
at java.net.URI$Parser.parseAuthority(URI.java:3155)
at java.net.URI$Parser.parseHierarchical(URI.java:3097)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:673)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String... args) throws Exception {
URI uri = new URI("http", null,"my_site.com", 9999, "/hello/world", "myparam=ABCDE", null);
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
public static void main(String... args) throws Exception {
URI uri = new URL("http://my_site.xyz.com:9999/hello/world?myparam=ABCDE").toUri();
}
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux john 4.4.0-93-generic #116-Ubuntu SMP Fri Aug 11 21:17:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
java.net.URI throws URISyntaxException when hostname contains underscore.
The following instruction will throw an URISyntaxException:
URI uriNotWorking = new URI("http", null,"my_site.xyz.com", 9999, "/hello/world", "myparam=ABCDE", null);
The following instruction will NOT throw an exception:
URI uriWorking = new URL("http://my_site.xyz.com:9999/hello/world?myparam=ABCDE").toUri();
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create an instance of java.net.URI such that the hostname contains an underscore:
URI uri = new URI("http", null,"my_site.xyz.com", 9999, "/hello/world", "myparam=ABCDE", null);
or
URI uri = new URI("http", null,"my_site.com", 9999, "/hello/world", "myparam=ABCDE", null);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Instance of java.net.URI pointing to the correct URL.
ACTUAL -
Thrown instance of java.net.URISyntaxException.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.net.URISyntaxException: Illegal character in hostname at index 9: http://my_site.com:9999/hello/world?myparam=ABCDE
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.parseHostname(URI.java:3387)
at java.net.URI$Parser.parseServer(URI.java:3236)
at java.net.URI$Parser.parseAuthority(URI.java:3155)
at java.net.URI$Parser.parseHierarchical(URI.java:3097)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:673)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public static void main(String... args) throws Exception {
URI uri = new URI("http", null,"my_site.com", 9999, "/hello/world", "myparam=ABCDE", null);
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
public static void main(String... args) throws Exception {
URI uri = new URL("http://my_site.xyz.com:9999/hello/world?myparam=ABCDE").toUri();
}
- duplicates
-
JDK-8180809 URI and URL conflicts with dealing with hostname contains underscore
-
- Open
-