java.lang.NullPointerException: null

Spring JIRA | Costi Ciudatu | 4 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    I spotted a NPE in my webmvc-based application log with the following stacktrace: {noformat} java.lang.NullPointerException: null at org.springframework.web.method.annotation.ModelFactory.findSessionAttributeArguments(ModelFactory.java:141) ~[spring-web-3.2.1.RELEASE.jar:3 .2.1.RELEASE] at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:99) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:722) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) ~[s pring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.1.R ELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) [servlet-api-3.0.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [servlet-api-3.0.jar:na] ............ {noformat} After digging into the code, I realized that the shared {{org.springframework.web.method.HandlerMethod}} instance is performing lazy initialization of its internal {{MethodParameter}} array without any synchronization. I therefore assume that the above error was due to one thread reading the array before the other one finished filling it. There's actually no other possible way that array could contain a null value. This assumption is also backed by the fact that the error occured immediately after a server restart and I haven't been able to reproduce it.

    Spring JIRA | 4 years ago | Costi Ciudatu
    java.lang.NullPointerException: null
  2. 0

    I spotted a NPE in my webmvc-based application log with the following stacktrace: {noformat} java.lang.NullPointerException: null at org.springframework.web.method.annotation.ModelFactory.findSessionAttributeArguments(ModelFactory.java:141) ~[spring-web-3.2.1.RELEASE.jar:3 .2.1.RELEASE] at org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:99) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:722) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) ~[s pring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.1.R ELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) [servlet-api-3.0.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) [servlet-api-3.0.jar:na] ............ {noformat} After digging into the code, I realized that the shared {{org.springframework.web.method.HandlerMethod}} instance is performing lazy initialization of its internal {{MethodParameter}} array without any synchronization. I therefore assume that the above error was due to one thread reading the array before the other one finished filling it. There's actually no other possible way that array could contain a null value. This assumption is also backed by the fact that the error occured immediately after a server restart and I haven't been able to reproduce it.

    Spring JIRA | 4 years ago | Costi Ciudatu
    java.lang.NullPointerException: null

    Root Cause Analysis

    1. java.lang.NullPointerException

      null

      at org.springframework.web.method.annotation.ModelFactory.findSessionAttributeArguments()
    2. Spring
      ModelFactory.initModel
      1. org.springframework.web.method.annotation.ModelFactory.findSessionAttributeArguments(ModelFactory.java:141)[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      2. org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:99)[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      2 frames
    3. Spring MVC
      FrameworkServlet.doGet
      1. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:722)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      3. org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      4. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      5. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      6. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      7. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      7 frames
    4. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:735)[servlet-api-3.0.jar:na]
      1 frame
    5. Spring MVC
      FrameworkServlet.service
      1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
      1 frame
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:848)[servlet-api-3.0.jar:na]
      1 frame