jersey
  1. jersey
  2. JERSEY-1753

Resuming an AsyncResponse with a WebApplicationException results in a NullPointerException

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-m12, 2.0
    • Fix Version/s: 2.0-rc1, 2.0
    • Component/s: containers
    • Labels:
      None

      Description

      When resuming an AsyncResponse with a WebApplicationException, ServerRuntime$Responder eventually calls release(ContainerResponse) twice (once in process(ContainerResponse) and then in the finally block of the process(Throwable) method. This results in a NullPointerException later in Grizzly (see stacktrace below).

      This seems to be an issue with the Grizzly container, as the same resource used in a unit-test with the InMemoryTestContainer doesn't throw.

      java.lang.NullPointerException
      	at org.glassfish.grizzly.http.server.Request.getAttribute(Request.java:835)
      	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyRequestPropertiesDelegate.getProperty(GrizzlyRequestPropertiesDelegate.java:67)
      	at org.glassfish.jersey.server.ContainerRequest.getProperty(ContainerRequest.java:245)
      	at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.getCloseables(CloseableServiceBinder.java:112)
      	at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.close(CloseableServiceBinder.java:92)
      	at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:473)
      	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:312)
      	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder$4.run(ServerRuntime.java:613)
      	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:293)
      	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:626)
      	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:610)
      

        Activity

        Hide
        t.broyer added a comment -

        Sorry, should have mentioned the stacktrace comes from a log in release, so here's the stacktrace with the log message. Also, the above stacktrace was with 2.0-M12, the below one is with 2.0-m12-1.

        févr. 26, 2013 1:08:50 PM org.glassfish.jersey.server.ServerRuntime$Responder release
        WARNING: Attempt to release single request processing resources has failed.
        java.lang.NullPointerException
        	at org.glassfish.grizzly.http.server.Request.getAttribute(Request.java:835)
        	at org.glassfish.jersey.grizzly2.httpserver.GrizzlyRequestPropertiesDelegate.getProperty(GrizzlyRequestPropertiesDelegate.java:67)
        	at org.glassfish.jersey.server.ContainerRequest.getProperty(ContainerRequest.java:245)
        	at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.getCloseables(CloseableServiceBinder.java:113)
        	at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.close(CloseableServiceBinder.java:93)
        	at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:477)
        	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:316)
        	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder$4.run(ServerRuntime.java:619)
        	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:294)
        	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:632)
        	at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:616)
        

        As a workaround, I use WebApplicationException#getResponse():

        if (t instanceof WebApplicationException) {
          ar.resume(((WebApplicationException) t).getResponse());
        } else {
          ar.resume(t);
        }
        
        Show
        t.broyer added a comment - Sorry, should have mentioned the stacktrace comes from a log in release , so here's the stacktrace with the log message. Also, the above stacktrace was with 2.0-M12, the below one is with 2.0-m12-1. févr. 26, 2013 1:08:50 PM org.glassfish.jersey.server.ServerRuntime$Responder release WARNING: Attempt to release single request processing resources has failed. java.lang.NullPointerException at org.glassfish.grizzly.http.server.Request.getAttribute(Request.java:835) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyRequestPropertiesDelegate.getProperty(GrizzlyRequestPropertiesDelegate.java:67) at org.glassfish.jersey.server.ContainerRequest.getProperty(ContainerRequest.java:245) at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.getCloseables(CloseableServiceBinder.java:113) at org.glassfish.jersey.server.internal.inject.CloseableServiceBinder$DefaultCloseableService.close(CloseableServiceBinder.java:93) at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:477) at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:316) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder$4.run(ServerRuntime.java:619) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:294) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:632) at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:616) As a workaround, I use WebApplicationException#getResponse() : if (t instanceof WebApplicationException) { ar.resume(((WebApplicationException) t).getResponse()); } else { ar.resume(t); }

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            t.broyer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 4 hours
              4h