JDK-8180809 : URI and URL conflicts with dealing with hostname contains underscore
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2017-05-20
  • Updated: 2018-11-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Hi, 

I am reporting a bug or an enhancement referring to the bug id [8132508](http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8132508). 

Referring the comments: 

```
RFC 952 disallows _ underscores in hostnames. So, this is not a bug. I also haven't been able to find examples of actual usage.
So, unless a particularly compelling case can be made, I'm closing as not a bug.
```

However, if hostname contains underscores is not a valid hostname, why it is in java.net.URL?  More clearly, valid in java.net.URL INvalid in java.net.URI. These issue often confused developers and cannot get the consistent on lot of third-part jars.

The following statements demonstrate this issue: 

new java.net.URI("http://test_1.tanglei.name").getHost() // = null
new java.net.URL("http://test_1.tanglei.name").getHost() // "test_1.tanglei.name" 

Wish your reply. 


JUSTIFICATION :
The following statements demonstrate this issue: 

new java.net.URI("http://test_1.tanglei.name").getHost() // = null
new java.net.URL("http://test_1.tanglei.name").getHost() // "test_1.tanglei.name" 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If the underscore is not valid in hostname, both URL and URI getHost should return null.
ACTUAL -
new java.net.URI("http://test_1.tanglei.name").getHost()  return null
new java.net.URL("http://test_1.tanglei.name").getHost() return "test_1.tanglei.name" 


Comments
$ ./build/macosx-x86_64-normal-server-release/images/jdk/bin/jshell | Welcome to JShell -- Version 12-internal | For an introduction type: /help intro jshell> var x = new java.net.URI("http://test_1.tanglei.name"); x ==> http://test_1.tanglei.name jshell> x.getAuthority(); $2 ==> "test_1.tanglei.name" jshell> x.getHost(); $3 ==> null jshell> x.getPort(); $4 ==> -1 jshell> x.parseServerAuthority(); | Exception java.net.URISyntaxException: Illegal character in hostname at index 11: http://test_1.tanglei.name | at URI$Parser.fail (URI.java:2915) | at URI$Parser.parseHostname (URI.java:3450) | at URI$Parser.parseServer (URI.java:3299) | at URI$Parser.parseAuthority (URI.java:3218) | at URI$Parser.parseHierarchical (URI.java:3160) | at URI$Parser.parse (URI.java:3116) | at URI.parseServerAuthority (URI.java:945) | at (#5:1) The authority is considered registry-based ( not server-based ).
04-09-2018