org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

Spring JIRA | Michael Osipov | 2 years ago
  1. 0

    Say I have this mapping: {code} <mvc:resources mapping="/docs/**" location="classpath:/docs/" /> {code} Request {{docs/}} or any other subdirectory ends up in a HTTP 500: {noformat} 19:27:23.669 [http-8081-2] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request java.io.FileNotFoundException: class path resource [docs/rest] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:407) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:241) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.41] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [catalina.jar:6.0.41] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.41] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:6.0.41] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.41] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) [catalina.jar:6.0.41] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) [tomcat-coyote.jar:6.0.41] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) [tomcat-coyote.jar:6.0.41] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.41] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67] {noformat} I would rather expect here 200 or better yet 204. The directory does exist but WebMVC does not know how to handle. I have debugged the implementation and {{Resource}} is retrieved but {{getInputStream}} fails. Moreover, content length is 0. I don't expect an extensive handling like in Apache`s {{mod_dir}} but at least not a 500. Meanwhile, I have applied this workaround: {code} <urlrewrite> <rule> <name>mod_dir fake</name> <from>^/docs(/rest)?$</from> <to type="permanent-redirect" last="true">%{context-path}/docs$1/</to> </rule> <rule> <name>mod_dir fake</name> <from>^/docs(.+)/$</from> <to last="true">/docs$1/index.html</to> </rule> </urlrewrite> {code}

    Spring JIRA | 2 years ago | Michael Osipov
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
  2. 0

    /assets/metrics yields NullPointerException

    GitHub | 2 years ago | prange
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    uberjar problem with Leiningen 2.3.3 (works with 2.3.2)

    Google Groups | 3 years ago | xavi
    java.lang.NullPointerException
  5. 0

    GitHub comment 41#12002709

    GitHub | 4 years ago | andeee
    java.lang.NullPointerException

    4 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at java.io.FilterInputStream.close()
    2. Java RT
      JarURLConnection$JarURLInputStream.close
      1. java.io.FilterInputStream.close(FilterInputStream.java:181)
      2. sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.close(JarURLConnection.java:108)
      2 frames
    3. Spring MVC
      FrameworkServlet.doGet
      1. org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:413)
      2. org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:241)
      3. org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
      4. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
      5. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
      6. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      7. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      7 frames
    4. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      1 frame
    5. Spring MVC
      FrameworkServlet.service
      1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      1 frame
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      1 frame
    7. Jetty
      QueuedThreadPool$3.run
      1. org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:717)
      2. org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1644)
      3. org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:171)
      4. org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1615)
      5. org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
      6. org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
      7. org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:568)
      8. org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
      9. org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1112)
      10. org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:479)
      11. org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
      12. org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1046)
      13. org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
      14. org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
      15. org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
      16. org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
      17. org.eclipse.jetty.server.Server.handle(Server.java:459)
      18. org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:281)
      19. org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:232)
      20. org.eclipse.jetty.io.AbstractConnection$1.run(AbstractConnection.java:505)
      21. org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
      22. org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
      22 frames
    8. Java RT
      Thread.run
      1. java.lang.Thread.run(Thread.java:745)
      1 frame