Issue Details (XML | Word | Printable)

Key: JETTY-842
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Jan Bartel
Reporter: Eirik Bjørsnøs
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Jetty

NPE when using HttpClient without a path component in the URL

Created: 25/Dec/08 05:17 PM   Updated: 20/Apr/09 01:07 AM
Component/s: Eclipse
Affects Version/s: 7.0.0pre3
Fix Version/s: 6.1.15.pre0

Time Tracking:
Not Specified


 Description  « Hide
Passing a URL without a trailing path component in HttpExchange.setURL() leads to a NullPointerException in HttpGenerator.java:281.

With:

ContentExchange exchange = new ContentExchange();
exchange.setMethod("GET");

the following works:

exchange.setURL("http://jetty.mortbay.org/");
client.send(exchange);

while this fails with an non-pretty NPE:

exchange.setURL("http://jetty.mortbay.org");
client.send(exchange);

java.lang.NullPointerException
at org.mortbay.jetty.HttpGenerator.completeHeader(HttpGenerator.java:281)
at org.mortbay.jetty.client.HttpConnection.commitRequest(HttpConnection.java:392)
at org.mortbay.jetty.client.HttpConnection.handle(HttpConnection.java:208)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:421)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:497)

I'd be happy to provide a patch if someone (Greg) can give me some input on desired behavior. I see the following options:

1) Do nothing
2) Throw an IllegalArgumentException with an explaination instead of the NPE. Reading the URL RFC I see that the "/" is not a part of the path component, so strictly speaking a URL without a path component should end with a "/".
3) Update setURL to add a "/" to the URL if the user didn't.

Since I'm the silly user who forgot my "/" in the first place, I'm personally in favor of option 3

Let me know what you think and I'll provide a patch.

Thanks,
Eirik.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jan Bartel added a comment - 29/Dec/08 05:35 AM
Eirik,

Thanks for pointing that one out. Fixed now in trunk and jetty-6 branch.
cheers
Jan