title: @ExceptionHandler null pointer in console after spring-boot upgrade
body: <p>Today, I was feeling a bit lucky, so I upgraded from Spring boot 1.5.1 to the latest. When I run my JAR file, everything seems fine at first.</p>
  
  <p>However, when I make a call that is expected to return an error response (negative test - say "record not found"), it returns a properly formatted JSON response as expected. </p>
  
  <p>However, I also notice a giant stack-trace in the console.</p>
  
  <p>There is a WARN level log which mentions a null pointer somewhere.</p>
  
  <pre><code>WARN  o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - 
  Failed to invoke @ExceptionHandler method: protected org.springframework.http.ResponseEntity&lt;?&gt;     com.sgb.AbstractBaseController.handle(com.sgb.panic.CustomSgbException,org.springframework.web.context.request.WebRequest)
  java.lang.NullPointerException: null
      at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
      at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:384)
      at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:59)
      at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)
      at org.springframework.web.servlet.handler.HandlerExceptionResolverComposite.resolveException(HandlerExceptionResolverComposite.java:74)
      at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1218)
      at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1030)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:664)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
  </code></pre>
  
  <p>It was working perfectly fine before I upgraded to the latest spring boot 1.5.3.
  When I switched back to 1.5.1, the stack trace goes away.
  I switch to 1.5.3, it comes back.</p>
  
  <p>What gives?
  Appreciate any pointers.</p>
  
  <p>EDIT:
  When I change the logging level of spring framework to DEBUG, I see that immediately after the above stack trace is logged, it attempts to call the ExceptionHandler again and succeeds the second time - which explains why a valid error response was coming despite the stack trace. </p>
  
  <p>The question then becomes why :</p>
  
  <pre><code> o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Invoking @ExceptionHandler method
  </code></pre>
  
  <p>the first invocation to @ExceptionHandler method is failing.</p>
  
  <p>EDIT:
  <a href="https://stackoverflow.com/questions/42871047/basic-springboot-app-throws-nullpointerexception">This SO post</a> also refers to this problem.</p>
  
  <p>In my case, I have an AbstractBaseController class that all my controllers extend where all the exception handling occurs instead of having a separate ControllerAdvice for my Rest endpoint.</p>
  
  <p>I attempted to create a separate ControllerAdvice for handling all exceptions. It works for all my custom exceptions, however when validation failure triggered by @Valid (JSR-303) occurs, it does not get seem to trigger my custom ExceptionHandler in my ControllerAdvice for MethodArgumentNotValidException. This results in an empty 400 with no error message when JSR 303 validations fail.</p>
  
  <p>So I need to move all my exception handlers back into the superclass for the controllers which results in the original WARN message in the log. This is less than ideal.</p>