| Summary: | NullPointerException when handling url http://a_b.com | ||
|---|---|---|---|
| Product: | [RT] Jetty | Reporter: | Junwei Sun <sunjunwei2> |
| Component: | client | Assignee: | Jan Bartel <janb> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | critical | ||
| Priority: | P3 | CC: | jetty-inbox |
| Version: | unspecified | ||
| Target Milestone: | 7.5.x | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
|
Description
Junwei Sun
Junwei, A bad host name such as "a_b" will now throw an IllegalArgumentException instead of a NPE. Fixed for 7.6.0. Jan Hi Jan, Actually, URL with "_" works in browser. So I think we can not just throw exception for such urls, but to support them. For example, I have url: http://basic_sounds.blogspot.com/ (In reply to comment #1) > Junwei, > > A bad host name such as "a_b" will now throw an IllegalArgumentException > instead of a NPE. Fixed for 7.6.0. > > Jan it should be supported. Hi Junwei,
Well, this is an interesting situation with the java URI and URL classes.
If you do:
URI uri = URI.create("http://basic_sounds.blogspot.com");
uri.getHost();
you get null.
On the other hand, if you do:
URI uri = URI.create("http://basic_sounds.blogspot.com");
URL url = uri.toURL();
url.getHost();
you get "basic_sounds.blogspot.com"
If you read about valid hostnames, "_" is not a valid character:
http://en.wikipedia.org/wiki/Hostname
So, I don't think we can second-guess the URI class and try and accommodate invalid chars in hostnames. Sun (now Oracle) were pretty clear about what is and is not considered a valid name here:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5049974
Now, what you can do is use a different jetty api to work around the invalid hostname. This will work:
HttpExchange.setRequestURI("http://basic_sounds.blogspot.com");
HttpExchange.setAddress(new Address("basic_sounds.blogspot.com", 80);
regards
Jan
(In reply to comment #3)
> it should be supported.
OK; I see; Thank you very much. |