NullPointerException in AbstractClientConnector :-(

I created a very simple application with two Views. The UI.init() creates a Navigator and registers two views via calls:

navigator.addView("", new LoginView());
navigator.addView("MainView", new MainView());

In the LoginView’s Button.ClickListener()'s buttonClick() method, I call
navigator.navigateTo(“MainView”);
When that call is made, the NullPointerException below happens. Does anyone have a clue what’s going on? Any help would be much appreciated.

I’m using the latest Vaadin (7.5.1) with Java 8u45.

tom

----- NullPointerException -------
java.lang.NullPointerException
at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:628)
at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:686)
at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:623)
at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:686)
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:568)
at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:150)
at com.vaadin.ui.UI.setContent(UI.java:1305)
at com.vaadin.navigator.Navigator$SingleComponentContainerViewDisplay.showView(Navigator.java:224)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:575)
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:527)
at com.lenovo.sat.satweb.LoginView$1.buttonClick(LoginView.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:995)
at com.vaadin.ui.Button.fireClick(Button.java:380)
at com.vaadin.ui.Button.click(Button.java:369)
at com.vaadin.ui.Button$ClickShortcut.handleAction(Button.java:548)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:238)
at com.vaadin.event.ConnectorActionManager.handleAction(ConnectorActionManager.java:81)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:233)
at com.vaadin.event.ActionManager.handleActions(ActionManager.java:216)
at com.vaadin.ui.UI.changeVariables(UI.java:390)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:508)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:327)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:202)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:95)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

As a follow-up to my own question: I noticed a couple Atmosphere-related severe warning during startup and wonder if has anything to do with the above error? Here are the two “SEVERE” messages in my Tomcat log:

Jul 21, 2015 8:32:58 AM org.atmosphere.cpr.DefaultAsyncSupportResolver newCometSupport
SEVERE: Failed to create comet support class: class org.atmosphere.container.JettyServlet30AsyncSupportWithWebSocket, error: null
Jul 21, 2015 8:32:58 AM org.atmosphere.cpr.DefaultAsyncSupportResolver newCometSupport
SEVERE: Switching to BlockingIO
Jul 21, 2015 8:32:58 AM org.atmosphere.cpr.AtmosphereFramework configureAtmosphereInterceptor

I never got an answer for this. I upgraded to 7.6.4 in the hope that this really old problem would be fixed - but it’s not. The only way I can avoid it is by overriding the detach() method with one that doesn’t do anything.

Hi Thomas, could you provide the stack trace you get with 7.6.4, with up-to-date line numbers? And of course, a minimal test case would be much appreciated. Do you happen to have DetachListeners added, or overridden detach methods in any child components?

Hi Johannes,
Thanks a bunch for helping me with this. I’m beginning to feel like I don’t understand some basic Vaadin concepts :frowning: Below is the stack trace. I’ve also attached a completely stripped down version of my app (minus the WEB-INF/lib, but that’s just the Vaadin libraries). Since I stripped out all but the most essential views, there are no DetachListeners or overridden detach() methods (I don’t think my full application had those either). The the three java files that make up the app are:

com.lenovo.lsat.ui.LSAT_UI.java
com.lenovo.lsat.ui.LoginView.java
com.lenovo.lsat.ui.MainView.java

Here’s the NullPointerException with the latest Vaadin 7.6.4:

java.lang.NullPointerException
    at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:641)
    at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:692)
    at com.vaadin.server.AbstractClientConnector.detach(AbstractClientConnector.java:636)
    at com.vaadin.ui.AbstractComponent.detach(AbstractComponent.java:692)
    at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:574)
    at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:150)
    at com.vaadin.ui.UI.setContent(UI.java:1312)
    at com.vaadin.navigator.Navigator$SingleComponentContainerViewDisplay.showView(Navigator.java:228)
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:611)
    at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:573)
    at com.lenovo.lsat.ui.LoginView$1.buttonClick(LoginView.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1008)
    at com.vaadin.ui.Button.fireClick(Button.java:377)
    at com.vaadin.ui.Button$1.click(Button.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158)
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:408)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:273)
    at com.vaadin.server.communication.PushHandler$2.run(PushHandler.java:149)
    at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:243)
    at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:503)
    at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:88)
    at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:78)
    at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:199)
    at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:107)
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:66)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2075)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:571)
    at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:333)
    at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:328)
    at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:425)
    at org.atmosphere.container.JSR356Endpoint$1.onMessage(JSR356Endpoint.java:213)
    at org.atmosphere.container.JSR356Endpoint$1.onMessage(JSR356Endpoint.java:210)
    at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:393)
    at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:494)
    at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:289)
    at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)
    at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
    at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Thanks again for your help,
Tom
24004.gz (120 KB)

Yeah, as I suspected the getUI call returns null which should not happen at that point of detach… unless there’s some race condition or something. I’ll check out your sample code.

Ah, the problem seems to be the overridden getUI method in MainView. If getUI always returns an instance, Vaadin thinks the component is always attached even when it’s not, and gets confused. Instead of passing a UI instance around, you should probably just call super.getUI() and cast it down. Or at least call super.getUI() and return null if it returns null.

Thanks!!! Changing getUI to downcast worked. To be honest, I didn’t even notice that I was overriding a superclass’ getUI() method. Knowing that CustomLayout includes that method will actually make my entire UI a bit more elegant as I won’t have to pass LSAT_UI into every screen I’m creating.

I would have never found this problem by looking at the stack trace (or even the warning given with the “-ea” JVM option). Thanks again.

No problem, I’m sorry you didn’t get an answer already eight months ago :frowning: I (and others) must have somehow missed this thread back then. But yes, all Vaadin components have getUI(), and internally whether a component is attached is defined in terms of getUI(), so overriding it (accidentally or not) is quite risky.