When calling ui.access(), Push fails and returns NPE.

I’m using a thread to handle the deletion of all the selected items in a grid.

In the ui.access() part I’m calling a refresh() method that queries from the database, and calls grid.setItems(updated list). My UI is obtained from a button’s event that triggers the deletion action (event.getSource().getUI().get()).

It works at random times, but most times I get the following error:

2018-04-25 10:29:20.199 [CommonExec-1-2]
 INFO  m.c.e.v.threads.MyThreadFactory - newThread(), getName = CommonExec-1-2, uncaughtException = {}

java.lang.RuntimeException: Push failed
	at com.vaadin.flow.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:194)
	at com.vaadin.flow.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:169)
	at com.vaadin.flow.component.UI.push(UI.java:567)
	at com.vaadin.flow.server.VaadinSession.unlock(VaadinSession.java:629)
	at com.vaadin.flow.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1916)
	at com.vaadin.flow.server.VaadinService.accessSession(VaadinService.java:1882)
	at com.vaadin.flow.server.VaadinSession.access(VaadinSession.java:923)
	at com.vaadin.flow.component.UI.access(UI.java:453)
	at my.com.elock.virsafe.ui.users.Users$3.run(Users.java:566)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
	at com.vaadin.flow.server.VaadinServlet.getApplicationUrl(VaadinServlet.java:530)
	at com.vaadin.flow.server.VaadinServletService.getMainDivId(VaadinServletService.java:140)
	at com.vaadin.flow.component.internal.UIInternals.getAppId(UIInternals.java:852)
	at com.vaadin.flow.component.notification.Notification.attachComponentTemplate(Notification.java:328)
	at com.vaadin.flow.component.notification.Notification.lambda$null$a21bdcc2$1(Notification.java:96)
	at com.vaadin.flow.internal.StateTree.lambda$runExecutionsBeforeClientResponse$1(StateTree.java:335)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at com.vaadin.flow.internal.StateTree.runExecutionsBeforeClientResponse(StateTree.java:332)
	at com.vaadin.flow.server.communication.UidlWriter.encodeChanges(UidlWriter.java:268)
	at com.vaadin.flow.server.communication.UidlWriter.createUidl(UidlWriter.java:123)
	at com.vaadin.flow.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:190)
	... 11 common frames omitted

It’s caused by https://github.com/vaadin/flow/issues/3798, which will be fixed in 10.0.0.beta9