MPR Vaadin 7 Navigator - sometimes session not set in Vaadin 7 UI element

In my pure Vaadin 7 app, I do the following:

  1. Browser tab one: login and do general setup
  2. Browser tab two: go to same website, and reload some settings if VaadinSession indicates certain things are true, else start from scratch ( forcing them to login )

I can do this because, in UI.init, I have the following:

		// Check session for login user.  If user in session, then use it.
		User sessionUser = WmsDataProvider.getCurrent().getLoginUser(true);
		if( sessionUser instanceof User 						&&
				sessionUser.getUserId() instanceof String 		&&
				!sessionUser.getUserId().trim().isEmpty()		&&
				sessionUser.getPassword() instanceof String	&&
				!sessionUser.getPassword().trim().isEmpty() )
			LoginView.doLogin(sessionUser.getUserId(), sessionUser.getPassword(),
					null/*registration id*/, null);
		else
			updateContent( null );

The updateContent(null); path is the initial step or when I need to start from scratch.

Now, Flow of course does not have the UI.init, so I was going to try to do it in my beforeEnter method of my root element ( Route("") ). But when my updateContent method creates the Navigator, the Vaadin 7 UI does not have a session. What am I doing wrong? What initialization step am I missing?

Sadly, I am not ready to move to a pure Flow Route ( no Navigator ), at least not unless I absolutely have to. Trying to minimize changes so I can give this to the users as soon as possible and stop supporting the pure Vaadin 7 version.

This is interesting, since I have recently been investigating issue that may indicate some trouble with session too https://github.com/vaadin/spring/issues/487 But I can’t yet conclude are we seeing different symptoms of the same root cause.

Updates:

  1. Changed from using BeforeEnterObserver to BeforeEnterListener, and adding UI.getCurrent().addBeforeEnterListener(this); to the entry point constructor. This did not fix the problem.
  2. Commented out UI.getCurrent().addBeforeEnterListener(this); in entry point and instead called my special code directly in the constructor, similar to what I do in init. This did not fix the problem.
  3. Currently merging my Vaadin 7 code into a Vaadin 14.0.0.rc7 version project. I was sort of worried about using 14.0.3 because it looked like it used a lot of the new npm stuff, and at the time, when I first tried it, it would not even run. Because it was not running, I could not tell if it was my migrated code or the 14.0.3 update. My next experiment will be to try 14.0.3 with the proper migration steps as defined the the Vaadin 14 MPR documentation.

What is interesting is that it consistently works when I first connect to the session, but does not when I connect to the same session again. It is like the MprUI stuff is not initialized yet. In fact, in the debugger, both the “session” element is null ( thus all this problem ). The flow UI looks perfect, and looks to be properly initialized.

Maybe the MPR UI stuff is not fully initialized until later in the process, like when components are attached?

Same results for Vaadin 14.0.0, and here is the except stack trace, if it helps ( I get the same stack trace for rc7 ):

java.lang.NullPointerException
	at com.vaadin.server.Page.getLocation(Page.java:940)
	at com.mobiwms.website.WmsNavigator.<init>(WmsNavigator.java:33)
	at com.mobiwms.website.view.MainView.<init>(MainView.java:89)
	at com.mobiwms.website.WmsEntryPoint.updateContent(WmsEntryPoint.java:310)
	at com.mobiwms.website.WmsEntryPoint.userLoginRequested(WmsEntryPoint.java:361)
	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.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:87)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:144)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:72)
	at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:67)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:108)
	at com.google.common.eventbus.EventBus.post(EventBus.java:212)
	at com.mobiwms.website.event.WmsEventBus.postWithThrows(WmsEventBus.java:29)
	at com.mobiwms.website.event.WmsEventBus.post(WmsEventBus.java:63)
	at com.mobiwms.website.view.login.LoginView.doLogin(LoginView.java:242)
	at com.mobiwms.website.WmsEntryPoint.beforeEnter(WmsEntryPoint.java:1007)
	at com.mobiwms.website.WmsEntryPoint.<init>(WmsEntryPoint.java:274)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:480)
	at com.vaadin.flow.internal.ReflectTools.createInstance(ReflectTools.java:448)
	at com.vaadin.flow.di.DefaultInstantiator.create(DefaultInstantiator.java:137)
	at com.vaadin.flow.di.DefaultInstantiator.getOrCreate(DefaultInstantiator.java:66)
	at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:158)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:127)
	at java.util.Optional.orElseGet(Optional.java:267)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:126)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChain(AbstractNavigationStateRenderer.java:314)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:195)
	at com.vaadin.flow.router.Router.handleNavigation(Router.java:223)
	at com.vaadin.flow.router.Router.navigate(Router.java:194)
	at com.vaadin.flow.router.Router.initializeUI(Router.java:92)
	at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1420)
	at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:456)
	at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540)
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:246)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:873)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1701)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1668)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:502)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:748)

Same exact results for 14.0.3. I figured I might as well bring this application to the latest, on the chance some change or bug fix since 14.0.0 fixes this issue, but I guess the issue is deeper than that.