title: NullPointerException on Spring class AbstractMessageConverterMethodProcessor
body: <p>I'm creating a Service where I'm validating a field. If the field is not ok with my rules, I throw a ResourceBusinessException, which is a class that I've created to deal with Unprocessable entities. However, when this exception is thrown, Spring throws a NullPointerException on the class AbstractMessageConverterMethodProcessor.</p>
  
  <p>To make it more readable of what I'm talking about, below I will attach all code that is related with this problem. To make it more simple, I have forced the exception on the code.</p>
  
  <p>First of all, my spring version:</p>
  
  <pre><code>&lt;spring-framework-version&gt;4.2.6.RELEASE&lt;/spring-framework-version&gt;
  </code></pre>
  
  <p>My Controller method:</p>
  
  <pre><code> /**
   * @param MyType
   * @return
   */
  @ApiOperation(value = "", notes = "", authorizations = { @Authorization(value = ApplicationSwaggerConfig.securityOAuth2, scopes = { @AuthorizationScope(scope = WRITE_SCOPE, description = WRITE_DESCRIPTION) }) })
  @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 201, message = "Created"), @ApiResponse(code = 401, message = "Unauthorized"),
  @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 422, message = "Unprocessable Entity") })
  @RequestMapping(value = "/xpto", method = POST, produces = { APPLICATION_XML_VALUE, APPLICATION_JSON_VALUE })
  public ResponseEntity&lt;Void&gt; saveXPTO(@RequestBody MyType myType) {
      Long tenantId = 1L;
      MyClass myObject = service.findMyClass(tenantId, empresaType.getAttribute());
      MyOtherClass myOtherObject= this.applyForOne(myObject);
      PreconditionsRest.checkCondition(false, "ERROR!!"); // This is where I'm forcing an error.
      contribuinteService.saveMyOtherObject(myOtherObject);
      return new ResponseEntity&lt;Void&gt;(new HttpHeaders(), CREATED);
  }
  </code></pre>
  
  <p>My service method:</p>
  
  <pre><code>/**
   * Check condition.
   *
   * @param condition O(a)(s) condition
   */
  public static void checkCondition(boolean condition, String message){
      if (!condition) {
          throw new ResourceBusinessException(message);
      }
  }
  </code></pre>
  
  <p>My ResourceBusinessException class:</p>
  
  <pre><code>public class ResourceBusinessException extends RuntimeException{
  
  private static final long serialVersionUID = 1L;
  
  
  private ErrorMessage errorMessage;
  
  
  public ResourceBusinessException() {
      super();
  }
  
  
  public ResourceBusinessException(String message, Throwable cause,boolean enableSuppression, boolean writableStackTrace) {
      super(message, cause, enableSuppression, writableStackTrace);
  }
  
  
  public ResourceBusinessException(String message, Throwable cause) {
      super(message, cause);
  }
  
  
  public ResourceBusinessException(String message) {
      super(message);
  }
  
  
  public ResourceBusinessException(Throwable cause) {
      super(cause);
  }
  
  
  public ResourceBusinessException(ErrorMessage errorMessage){
      super(errorMessage.getDetail());
      this.errorMessage = errorMessage;
  }
  
  
  public ErrorMessage getErrorMessage() {
      return errorMessage;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My ResourceBusinessExceptionHandler class :</p>
  
  <pre><code>public class ResourceBusinessExceptionHandler extends ErrorMessageRestExceptionHandler&lt;ResourceBusinessException&gt;{
  
  
  private static final Logger LOGGER = LoggerFactory.getLogger(ResourceBusinessExceptionHandler.class);
  
  private ErrorMessage errorMessage;
  
  public ResourceBusinessExceptionHandler() {
      super(UNPROCESSABLE_ENTITY);
  }
  
  
  @Override
  public ErrorMessage createBody(ResourceBusinessException ex, HttpServletRequest req) {
      LOGGER.debug("ResourceBusinessExceptionHandler - Started");
      ErrorMessage tmpl = super.createBody(ex, req);
      ValidationErrorMessage msg = new ValidationErrorMessage(tmpl);
      errorMessage=ex.getErrorMessage();
      if(errorMessage==null){
          errorMessage = new ErrorMessage();
      }
      msg.setType(ResourceHandlerUtil.getType(errorMessage,UNPROCESSABLE_ENTITY_SPEC));
      msg.setTitle(ResourceHandlerUtil.getTitle(errorMessage,HttpStatus.UNPROCESSABLE_ENTITY));
      msg.setDetail(ResourceHandlerUtil.getDetail(errorMessage,HttpStatus.UNPROCESSABLE_ENTITY));
      msg.setInstance(ResourceHandlerUtil.getUriInstance(errorMessage,UNPROCESSABLE_ENTITY_URI));
      LOGGER.debug("ResourceBusinessExceptionHandler - Complete");
      return msg;
  }
  </code></pre>
  
  <p>My configuration bean:</p>
  
  <pre><code>&lt;bean id="compositeExceptionResolver" class="org.springframework.web.servlet.handler.HandlerExceptionResolverComposite"&gt;
      &lt;property name="order" value="0" /&gt;
      &lt;property name="exceptionResolvers"&gt;
          &lt;list&gt;
              &lt;ref bean="exceptionHandlerExceptionResolver" /&gt;
              &lt;ref bean="restExceptionResolver" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
      &lt;bean id="restExceptionResolver" class="cz.jirutka.spring.exhandler.RestHandlerExceptionResolverFactoryBean"&gt;
      &lt;property name="messageSource" ref="httpErrorMessageSource" /&gt;
      &lt;property name="defaultContentType" value="application/json" /&gt;
      &lt;property name="exceptionHandlers"&gt;
          &lt;map&gt;
              &lt;!-- 422 --&gt;
              &lt;entry key="com.company.project.exception.ResourceBusinessException"&gt;
                  &lt;bean class="com.company.project.exception.handler.ResourceBusinessExceptionHandler"/&gt;
              &lt;/entry&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;&lt;bean id="exceptionHandlerExceptionResolver" class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"/&gt;
  
  &lt;bean id="httpErrorMessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource" p:defaultEncoding="UTF-8"/&gt;
  </code></pre>
  
  <p>Then, when I make a request to my service, the following stack trace appears on my console :</p>
  
  <blockquote>
    <p>15:26:09.119 [http-nio-8013-exec-3] DEBUG c.j.s.e.h.RestExceptionHandler - POST /api/xpto ~> 422
    com.company.project.exception.ResourceBusinessException: ERROR!!</p>
  </blockquote>
  
  <p>[...] And then, the NullPointerException...</p>
  
  <blockquote>
    <p>ERROR c.j.s.e.RestHandlerExceptionResolver - Failed to process error response: &lt;422 Unprocessable Entity,ValidationErrorMessage(errors=[]),{}>
    java.lang.NullPointerException: null
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.getGenericType(AbstractMessageConverterMethodProcessor.java:271) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:172) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:183) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at cz.jirutka.spring.exhandler.RestHandlerExceptionResolver.processResponse(RestHandlerExceptionResolver.java:141) ~[spring-rest-exception-handler-1.0.3.jar:1.0.3]
        at cz.jirutka.spring.exhandler.RestHandlerExceptionResolver.doResolveException(RestHandlerExceptionResolver.java:107) ~[spring-rest-exception-handler-1.0.3.jar:1.0.3]
        at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:137) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1185) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1022) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:973) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [servlet-api.jar:na]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.36]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.36]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.36]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.36]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.36]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.36]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.36]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.36]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.36]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.36]
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.36]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.36]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) [catalina.jar:8.0.36]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) [tomcat-coyote.jar:8.0.36]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670) [tomcat-coyote.jar:8.0.36]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) [tomcat-coyote.jar:8.0.36]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) [tomcat-coyote.jar:8.0.36]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.36]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]</p>
  </blockquote>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Below follows the method processResponse of the class RestHanlderExceptionResolver:</p>
  
  <pre><code>  protected void processResponse(ResponseEntity&lt;?&gt; entity, NativeWebRequest webRequest) throws Exception {
  
      ModelAndViewContainer mavContainer = new ModelAndViewContainer();
      try {
          responseProcessor.handleReturnValue(entity, null, mavContainer, webRequest);
  
      } catch (HttpMediaTypeNotAcceptableException ex) {
          LOG.debug("Requested media type is not supported, falling back to default one");
          fallbackResponseProcessor.handleReturnValue(entity, null, mavContainer, webRequest);
      }
  }
  </code></pre>