Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-672

ExceptionMapper returning null causes NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.3.4.Final
    • 2.2.0.GA, 2.3.1
    • jaxrs
    • None
    • Hide

      1. Register an exception mapper which returns null.
      2. Throw the registered exception.

      Show
      1. Register an exception mapper which returns null. 2. Throw the registered exception.
    • Low

      I also checked 2.3.1 version and the same code is present there as well as in 2.2.0.ga.

      org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
      	at org.jboss.resteasy.core.SynchronousDispatcher.writeFailure(SynchronousDispatcher.java:429)
      	at org.jboss.resteasy.core.SynchronousDispatcher.executeExceptionMapper(SynchronousDispatcher.java:313)
      	at org.jboss.resteasy.core.SynchronousDispatcher.handleReaderException(SynchronousDispatcher.java:392)
      	at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:222)
      	at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)
      	at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534)
      	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
      	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
      	at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
      	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
      	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      ...
      Caused by: java.lang.NullPointerException
      	at org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:563)
      	at org.jboss.resteasy.core.SynchronousDispatcher.writeFailure(SynchronousDispatcher.java:416)
      	... 44 more
      

      The problem is following in SynchronousDispatcher.java:

      public boolean executeExceptionMapper(HttpRequest request, HttpResponse response, Throwable exception)
      	writeFailure(request, response, mapper.toResponse(exception));    // returns null what is allowed according to the ExceptionMapper.toResponse javadoc
      
      
      protected void writeFailure(HttpRequest request, HttpResponse response, Response jaxrsResponse)
          writeJaxrsResponse(request, response, jaxrsResponse);       // calls writeJaxrsResponse without a null-pointer check
          
      protected void writeJaxrsResponse(HttpRequest request, HttpResponse response, Response jaxrsResponse)
                 throws WriterException
          Object type = jaxrsResponse.getMetadata().getFirst(   // jaxrsResponse is null, NPE is thrown
                    HttpHeaderNames.CONTENT_TYPE);
      

            patriot1burke@gmail.com Bill Burke (Inactive)
            coresystems_pem Martin Petras (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: