Issue Details (XML | Word | Printable)

Key: JERSEY-1753
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Michal Gajdos
Reporter: t.broyer
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jersey

Resuming an AsyncResponse with a WebApplicationException results in a NullPointerException

Created: 26/Feb/13 11:55 AM   Updated: 26/Mar/13 11:12 AM   Resolved: 21/Mar/13 09:31 PM
Component/s: containers
Affects Version/s: 2.0-m12, 2.0
Fix Version/s: 2.0-rc1, 2.0

Time Tracking:
Original Estimate: Not Specified
Remaining Estimate: 0 minutes
Remaining Estimate - 0 minutes
Time Spent: 4 hours
Time Spent - 4 hours

Tags:
Participants: Michal Gajdos and t.broyer


 Description  « Hide

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)


t.broyer added a comment - 26/Feb/13 12:11 PM

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