jersey
  1. jersey
  2. JERSEY-1525

Exception in a ContainerRequestFilter is not catched by exceptionMapper

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Invalid
    • Affects Version/s: 2.0-m09
    • Fix Version/s: 2.0-rc1, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      public class Filter implements ContainerResponseFilter {
      	@Override
      	public void filter(ContainerRequestContext requestContext,
      			ContainerResponseContext responseContext) throws IOException {
                  String x=null;
                  x.toString(); //Throws NPE
              }
      }
      @Provider
      public class ErrorHandler implements ExceptionMapper<Throwable> {
      
      	@Override
      	public Response toResponse(Throwable throwable) {
      		throwable.printStackTrace();
      		return Response.status(Status.NOT_ACCEPTABLE).build();
      	}
      
      }
      

      Error handler is not used for thrown NPE.

        Activity

        Hide
        Marek Potociar added a comment -

        Note that the above code is doomed to fail. The mapped exception will be processed by the filter again and that would throw the NPE again... The second NPE is not mapped (as per spec sect. 4.5) again, but propagated to the hosting container.

        I have added a Jersey E2E test that verifies that if an exception is only thrown once in the response filter, it get's mapped and the mapped response is propagated back to the client (after being processed by the filter chain again).

        Show
        Marek Potociar added a comment - Note that the above code is doomed to fail. The mapped exception will be processed by the filter again and that would throw the NPE again... The second NPE is not mapped (as per spec sect. 4.5) again, but propagated to the hosting container. I have added a Jersey E2E test that verifies that if an exception is only thrown once in the response filter, it get's mapped and the mapped response is propagated back to the client (after being processed by the filter chain again).

          People

          • Assignee:
            Marek Potociar
            Reporter:
            jan.supol
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 2 hours Time Not Required
              2h