Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 358027 - NullPointerException in ResourceHandler with jetty-stylesheet.css
Summary: NullPointerException in ResourceHandler with jetty-stylesheet.css
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: 8.0.1   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: 7.5.x   Edit
Assignee: Jan Bartel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-18 13:17 EDT by Andres Kalle CLA
Modified: 2011-09-19 03:59 EDT (History)
2 users (show)

See Also:


Attachments
Server configuration for reproducing the bug (582 bytes, text/xml)
2011-09-18 13:17 EDT, Andres Kalle CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andres Kalle CLA 2011-09-18 13:17:26 EDT
Created attachment 203555 [details]
Server configuration for reproducing the bug

Low priority - I only stumbled on this because I'd been studying the source code and noticed the hardcoded filename.
From the end user's perspective, they just get a different error where they should be getting a 404 error.

----

Steps to reproduce:

1. Use the attached XML to launch a lightweight Jetty instance, for example java -jar start.jar --ini reproduce.xml
(edit the port and resourceBase if needed)

2. Make sure there's no jetty-stylesheet.css file in the resourceBase folder.

2. Go to http://localhost:30303/jetty-stylesheet.css

The server console shows:

java.lang.NullPointerException
        at org.eclipse.jetty.server.handler.ResourceHandler.handle(ResourceHandler.java:356)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
        at org.eclipse.jetty.server.Server.handle(Server.java:350)
        at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:442)
        at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:910)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:565)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:217)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:46)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:545)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:43)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
        at java.lang.Thread.run(Unknown Source)

Code snippet from ResourceHandler:

...
Resource resource = getResource(request);
if (resource==null || !resource.exists())
{
    if (target.endsWith("/jetty-stylesheet.css"))
    {	
        response.setContentType("text/css");
        resource = getStylesheet();
    }
    else 
        return;
}
    
if (!_aliases && resource.getAlias()!=null)
...

The exception occurs on the last line. Looks like getStylesheet() returns null.

----

I also found two comment inaccuracies in the same source file and creating separate bug reports for these might be a bit of an overkill:

1. The class javadoc says "Requests that cannot be handled are let pass (Eg no 404's)", but this example does produce 404 errors with other non-existent filenames.

2. The javadoc for the handle() method refers to org.eclipse.jetty.server.server.Handler, which contains an extra ".server" - should be org.eclipse.jetty.server.Handler
Comment 1 Jan Bartel CLA 2011-09-19 03:59:03 EDT
Fixed for 7.5.2.