Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-639

NPE in ServerWebSocketContainer.doUpgrade

XMLWordPrintable

      Commit 670962 updated ServerWebSocketContainer such that contextToAddFilter can be set to null (from the handleAddingFilterMapping) method.

      This can cause a NullPointerException later in the doUpgrade method since the following line doesn't guard for null:

      WebSocketDeploymentInfo info = (WebSocketDeploymentInfo)contextToAddFilter.getAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME);
      

      .

      Here's a complete stack trace:

      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://localhost:65179/echo/websocket; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Servlet request failed to upgrade to WebSocket: http://localhost:65179/echo/websocket; nested exception is javax.servlet.ServletException: java.lang.NullPointerException
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:984) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:863) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet-api-3.1.0.jar:3.1.0]
      	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:848) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
      	at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:129) ~[undertow-websockets-jsr-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:237) ~[classes/:na]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:101) ~[classes/:na]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) ~[classes/:na]
      	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174) ~[undertow-servlet-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) ~[undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793) [undertow-core-1.3.17.Final.jar:1.3.17.Final]
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40]
      	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
      Caused by: org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://localhost:65179/echo/websocket; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Servlet request failed to upgrade to WebSocket: http://localhost:65179/echo/websocket; nested exception is javax.servlet.ServletException: java.lang.NullPointerException
      	at org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler.handleRequest(SockJsHttpRequestHandler.java:135) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:972) ~[spring-webmvc-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	... 59 common frames omitted
      Caused by: org.springframework.web.socket.server.HandshakeFailureException: Servlet request failed to upgrade to WebSocket: http://localhost:65179/echo/websocket; nested exception is javax.servlet.ServletException: java.lang.NullPointerException
      	at org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy.upgradeInternal(UndertowRequestUpgradeStrategy.java:113) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.upgrade(AbstractStandardUpgradeStrategy.java:119) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.server.support.AbstractHandshakeHandler.doHandshake(AbstractHandshakeHandler.java:281) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler.doHandshake(WebSocketTransportHandler.java:130) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService.handleRawWebSocketRequest(TransportHandlingSockJsService.java:206) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.sockjs.support.AbstractSockJsService.handleRequest(AbstractSockJsService.java:391) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	at org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler.handleRequest(SockJsHttpRequestHandler.java:132) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	... 63 common frames omitted
      Caused by: javax.servlet.ServletException: java.lang.NullPointerException
      	at io.undertow.websockets.jsr.ServerWebSocketContainer.doUpgrade(ServerWebSocketContainer.java:421) ~[undertow-websockets-jsr-1.3.17.Final.jar:1.3.17.Final]
      	at org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy.upgradeInternal(UndertowRequestUpgradeStrategy.java:110) ~[spring-websocket-4.3.0.BUILD-SNAPSHOT.jar:4.3.0.BUILD-SNAPSHOT]
      	... 69 common frames omitted
      Caused by: java.lang.NullPointerException: null
      	at io.undertow.websockets.jsr.ServerWebSocketContainer.doUpgrade(ServerWebSocketContainer.java:387) ~[undertow-websockets-jsr-1.3.17.Final.jar:1.3.17.Final]
      	... 70 common frames omitted
      

      Additional details can be found in SPR-13964

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              pwebb-1 Phillip Webb (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: