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));

user375868
  • 1,288
  • 4
  • 21
  • 45

2 Answers2

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.

christopher
  • 26,815
  • 5
  • 55
  • 89
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.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216