Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335500 - request.getParts() throws a NullPointerException
Summary: request.getParts() throws a NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 7.2.x   Edit
Assignee: Jan Bartel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-26 14:31 EST by Patrick CLA
Modified: 2011-01-27 10:56 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick CLA 2011-01-26 14:31:34 EST
Build Identifier: 8.0.0.M2

The following code throws a NullPointerException when I call it using curl.
Here are the details from the exception.

2011-01-26 11:30:09.862:INFO::jetty-8.0.0.M2
2011-01-26 11:30:09.904:INFO::Started SelectChannelConnector@0.0.0.0:8080
java.lang.NullPointerException
	at java.io.File.<init>(File.java:222)
	at org.eclipse.jetty.util.MultiPartInputStream.<init>(MultiPartInputStream.java:297)
	at org.eclipse.jetty.server.Request.getParts(Request.java:1914)
	at HelloWorld.handle(HelloWorld.java:22)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:114)
	at org.eclipse.jetty.server.Server.handle(Server.java:353)
	at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:598)
	at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1059)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:599)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:212)
	at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:427)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:510)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.access$000(SelectChannelEndPoint.java:34)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:450)
	at java.lang.Thread.run(Thread.java:680)



Reproducible: Always

Steps to Reproduce:
1. Run the following code.

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import java.util.Collection;
import javax.servlet.http.Part;

public class HelloWorld extends AbstractHandler {
    public void handle(String target,
                       Request baseRequest,
                       HttpServletRequest request,
                       HttpServletResponse response) 
        throws IOException, ServletException {
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        baseRequest.setHandled(true);
        
        try {
        	Collection<Part> parts = request.getParts();
        	for (Part part : parts) {
        		response.getWriter().println(part.getName());
        	}
        } catch (Exception e) {
        	e.printStackTrace();
        }

        response.getWriter().println("<h1>Hello World</h1>");
    }
 
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        server.setHandler(new HelloWorld());
 
        server.start();
        server.join();
    }
}

2. Run the following command.

curl -F param1=param1 -F param2=param2 http://localhost:8080/

3. Notice the thrown exception produced in the sample code.
Comment 1 Jan Bartel CLA 2011-01-26 17:39:59 EST
Silly bug. Fixed in rev 2700.

Jan
Comment 2 Patrick CLA 2011-01-27 10:56:13 EST
It looks like it's working now. You're a rock star Jan, Thanks!