Jetty

NPE when using HttpClient without a path component in the URL

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 7.0.0pre3
  • Fix Version/s: 6.1.15.pre0
  • Component/s: Eclipse
  • Labels:
    None
  • Number of attachments :
    0

Description

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.

Activity

Hide
Jan Bartel added a comment -

Eirik,

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

Show
Jan Bartel added a comment - Eirik, Thanks for pointing that one out. Fixed now in trunk and jetty-6 branch. cheers Jan

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: