0

Someone has submiited a bug to JDK, saying that hostname contains underscore(_) is not valid url. The following was the response. reference link

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.

I am wondering, if hostname with underscore is not valid, why the result is differrent between java.net.URI and java.net.URL? Is it a bug or a feature? Here is the example.

java.net.URL url = new java.net.URL("http://test_1.tanglei.name");
System.out.println(url.getHost()); //test_1.tanglei.name
java.net.URI uri = new java.net.URI("http://test_1.tanglei.name");
System.out.println(uri.getHost()); //null 
2

1 Answer 1

1

Is it a bug or a feature?

I don't think the reviewer entirely understood that you were talking about 3-way inconsistency between two different URI constructors and the 4 arg URL constructor. (Your bug report does not spell out precisely which of the inconsistencies is concerning you.) He has viewed it as a report as a 2-way inconsistency between URL and URI.

The review is somewhat terse, but the reviewer's point is the URL constructor is behaving in accordance with its specification. Since the specification explicitly states that no validation is performed, this is not a bug in the code. This is indisputable.

What he didn't spell out is that fixing this inconsistency (by changing the URL class specification) would break lots of peoples' 20+ year old code Java code. That would be a really bad idea. It can't happen.

So ... this inconsistency is a "feature".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.