0

I am following this tutorial -

When I send request like this-

http://localhost:9090/AsyncServlet?id=99&dispatch=true&timeout=false

I am getting following-

Apr 09, 2013 4:01:09 PM com.mycompany.mavenproject1.AsyncServlet doGet
INFO: AsyncServlet: Processing request: 99. on thread: 27:qtp2072997125-27[4/9/13 4:01 PM]
2013-04-09 16:01:09.503:WARN:oejs.ServletHandler:/AsyncServlet
java.lang.NullPointerException
    at com.mycompany.mavenproject1.AsyncServlet.doGet(AsyncServlet.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:368)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Thread.java:722)

I just don't know even where to start debugging. My web.xml looks like this-

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"> 

<servlet>
    <servlet-name>AsyncServlet</servlet-name>
    <servlet-class>com.mycompany.mavenproject1.AsyncServlet
    </servlet-class>        
    <async-supported>true</async-supported>

</servlet>
<servlet-mapping>
    <servlet-name>AsyncServlet</servlet-name>
    <url-pattern>/AsyncServlet/*</url-pattern>
</servlet-mapping>

</web-app>

Line50: executor.execute(new AsyncRequestProcessor(asyncCtx, dispatch));

4
  • 1
    Check the line at AsyncServlet.java:50. Commented Apr 9, 2013 at 23:07
  • 1
    And what, may I ask, is on line 50? Commented Apr 9, 2013 at 23:07
  • Start debugging at line 50 of AsyncServlet.java. Commented Apr 9, 2013 at 23:08
  • updated with line50 content Commented Apr 9, 2013 at 23:17

2 Answers 2

1

If line 50 is this:

executor.execute(new AsyncRequestProcessor(asyncCtx, dispatch));

then the most likely immediate cause of the NPE is that executor is null.

If asyncCtx or dispatch where boxed primitive types, then you could get an NPE from unboxing null. However this seems highly unlikely given the names of the variables. They look like names of "regular" class instances to me.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right, I executed System.out.println(request.getAttribute("executor")); and got Null
1

The only thing that could force a NullPointerException to be thrown from that line is if the executor object has not been intialised properly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.