I have a view called UserDetails with the following in it
@Override
public void setParameter(BeforeEvent event, @OptionalParameter Long userId) {
this.userId = userId;
}
@Override
public void afterNavigation(AfterNavigationEvent event) {
user = userRepository.findById(userId).get();
binder.readBean(user);
deviceList = deviceRepository.findByDeviceOwner(user.getUserUsername());
deviceGrid.setItems(deviceList);
deviceGrid.setColumns("deviceName", "deviceType", "deviceModel");
deviceGrid.asSingleSelect().addValueChangeListener(e -> {
UI.getCurrent().navigate("devices/details/" + e.getValue().getId());
});
}
So deviceList is populated by getting the userId from the url parameter and then finding all devices owned by that user, a grid is made from that list, and then a ValueChangeListener is attached to that grid that allows for navigating to a view for that specific device (DeviceDetails). On that view it’s possible to “check in” the device and remove yourself as a device owner. The problem I’m having is that if a user:
Navigates to UserDetails
Navigates to a device they own and removes that ownership
Navigates back to the UserDetails page
I get a NullPointerException that prevents the view from being loaded. Something that happens during that process fixes it, though, because all following attempts to open the view work perfectly.
inventoryapp_1 | java.lang.NullPointerException: null
inventoryapp_1 | at com.company.inventoryapp.user.UserDetails.lambda$afterNavigation$6566464a$1(UserDetails.java:171) ~[inventoryapp/:na]
inventoryapp_1 | at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel$1.lambda$addValueChangeListener$864f22c8$1(AbstractGridSingleSelectionModel.java:135) ~[vaadin-grid-flow-3.0.3.jar:na]
inventoryapp_1 | at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205) ~[flow-server-1.4.3.jar:1.4.3]
inventoryapp_1 | at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194) ~[flow-server-1.4.3.jar:1.4.3]
inventoryapp_1 | at com.vaadin.flow.component.Component.fireEvent(Component.java:358) ~[flow-server-1.4.3.jar:1.4.3]
inventoryapp_1 | at com.vaadin.flow.component.grid.Grid.access$100(Grid.java:123) ~[vaadin-grid-flow-3.0.3.jar:na]
inventoryapp_1 | at com.vaadin.flow.component.grid.Grid$SelectionMode$1$1.fireSelectionEvent(Grid.java:209) ~[vaadin-grid-flow-3.0.3.jar:na]
inventoryapp_1 | at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.doSelect(AbstractGridSingleSelectionModel.java:194) ~[vaadin-grid-flow-3.0.3.jar:na]
inventoryapp_1 | at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.select(AbstractGridSingleSelectionModel.java:75) ~[vaadin-grid-flow-3.0.3.jar:na]
inventoryapp_1 | at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.deselect(AbstractGridSingleSelectionModel.java:96) ~[vaadin-grid-flow-3.0.3.jar:na]
...continues...
I’m at a loss for how to fix this. It seems like the deviceList reloads itself once the page is loaded, but during that time there’s also an error. Is there some way for me to clear the ValueChangeListener?
I think the value change listener is added in the wrong place; when in this method, a new listener gets added each time the view is navigated to. Try moving that registration to e.g. the constructor and see if that helps.
If the problem still occurs, there’s a few things you can try. My guess is that the selection is re-set when you call setItems (the stacktrace should show this, but you didn’t list the full stack so I can’t be sure).
The event you get in the listener (‘e’) has a boolean that tells you if the change originated from the user or not, you could check that and only navigate if the user selected the value (this may break other logic if you rely on programmatically selecting things as well).
The final option is the old tried-and-true way of creating a class variable boolean ignoreValueChange and use that;
Here’s the full stack trace with the addValueChangeListener in the afterNavigation method:
java.lang.NullPointerException
at com.company.inventoryapp.user.UserDetails.lambda$afterNavigation$6566464a$1(UserDetails.java:170)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel$1.lambda$addValueChangeListener$864f22c8$1(AbstractGridSingleSelectionModel.java:135)
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205)
at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194)
at com.vaadin.flow.component.Component.fireEvent(Component.java:358)
at com.vaadin.flow.component.grid.Grid.access$100(Grid.java:123)
at com.vaadin.flow.component.grid.Grid$SelectionMode$1$1.fireSelectionEvent(Grid.java:209)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.doSelect(AbstractGridSingleSelectionModel.java:194)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.select(AbstractGridSingleSelectionModel.java:75)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.deselect(AbstractGridSingleSelectionModel.java:96)
at java.util.Optional.ifPresent(Optional.java:159)
at com.vaadin.flow.data.selection.SelectionModel$Single.setSelectedItem(SelectionModel.java:86)
at com.vaadin.flow.data.selection.SelectionModel$Single.deselectAll(SelectionModel.java:92)
at com.vaadin.flow.component.grid.Grid.deselectAll(Grid.java:2398)
at com.vaadin.flow.component.grid.Grid.setDataProvider(Grid.java:2165)
at com.vaadin.flow.data.binder.HasDataProvider.setItems(HasDataProvider.java:50)
at com.elavon.inventoryapp.user.UserDetails.afterNavigation(UserDetails.java:164)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$fireAfterNavigationListeners$2(AbstractNavigationStateRenderer.java:305)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.fireAfterNavigationListeners(AbstractNavigationStateRenderer.java:305)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:235)
at com.vaadin.flow.router.Router.handleNavigation(Router.java:219)
at com.vaadin.flow.router.Router.navigate(Router.java:190)
at com.vaadin.flow.component.UI.navigate(UI.java:867)
at com.vaadin.flow.component.UI.navigate(UI.java:830)
at com.elavon.inventoryapp.user.UserView.lambda$new$e2b03932$6(UserView.java:149)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel$1.lambda$addValueChangeListener$864f22c8$1(AbstractGridSingleSelectionModel.java:135)
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205)
at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194)
at com.vaadin.flow.component.Component.fireEvent(Component.java:358)
at com.vaadin.flow.component.grid.Grid.access$100(Grid.java:123)
at com.vaadin.flow.component.grid.Grid$SelectionMode$1$1.fireSelectionEvent(Grid.java:209)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.doSelect(AbstractGridSingleSelectionModel.java:194)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.selectFromClient(AbstractGridSingleSelectionModel.java:66)
at com.vaadin.flow.component.grid.Grid.select(Grid.java:2748)
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.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:167)
at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:129)
at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.handleNode(PublishedServerEventHandlerRpcHandler.java:117)
at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:64)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:387)
at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:368)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:368)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:310)
at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:89)
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1507)
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:242)
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:352)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:155)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:52)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
And then for moving it to the constructor:
java.lang.NullPointerException
at com.company.inventoryapp.user.UserDetails.lambda$new$2048df10$1(UserDetails.java:89)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel$1.lambda$addValueChangeListener$864f22c8$1(AbstractGridSingleSelectionModel.java:135)
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205)
at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194)
at com.vaadin.flow.component.Component.fireEvent(Component.java:358)
at com.vaadin.flow.component.grid.Grid.access$100(Grid.java:123)
at com.vaadin.flow.component.grid.Grid$SelectionMode$1$1.fireSelectionEvent(Grid.java:209)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.doSelect(AbstractGridSingleSelectionModel.java:194)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.select(AbstractGridSingleSelectionModel.java:75)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.deselect(AbstractGridSingleSelectionModel.java:96)
at java.util.Optional.ifPresent(Optional.java:159)
at com.vaadin.flow.data.selection.SelectionModel$Single.setSelectedItem(SelectionModel.java:86)
at com.vaadin.flow.data.selection.SelectionModel$Single.deselectAll(SelectionModel.java:92)
at com.vaadin.flow.component.grid.Grid.deselectAll(Grid.java:2398)
at com.vaadin.flow.component.grid.Grid.setDataProvider(Grid.java:2165)
at com.vaadin.flow.data.binder.HasDataProvider.setItems(HasDataProvider.java:50)
at com.elavon.inventoryapp.user.UserDetails.afterNavigation(UserDetails.java:168)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$fireAfterNavigationListeners$2(AbstractNavigationStateRenderer.java:305)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.fireAfterNavigationListeners(AbstractNavigationStateRenderer.java:305)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:235)
at com.vaadin.flow.router.Router.handleNavigation(Router.java:219)
at com.vaadin.flow.router.Router.navigate(Router.java:190)
at com.vaadin.flow.component.UI.navigate(UI.java:867)
at com.vaadin.flow.component.UI.navigate(UI.java:830)
at com.elavon.inventoryapp.user.UserView.lambda$new$e2b03932$6(UserView.java:149)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel$1.lambda$addValueChangeListener$864f22c8$1(AbstractGridSingleSelectionModel.java:135)
at com.vaadin.flow.component.ComponentEventBus.fireEventForListener(ComponentEventBus.java:205)
at com.vaadin.flow.component.ComponentEventBus.fireEvent(ComponentEventBus.java:194)
at com.vaadin.flow.component.Component.fireEvent(Component.java:358)
at com.vaadin.flow.component.grid.Grid.access$100(Grid.java:123)
at com.vaadin.flow.component.grid.Grid$SelectionMode$1$1.fireSelectionEvent(Grid.java:209)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.doSelect(AbstractGridSingleSelectionModel.java:194)
at com.vaadin.flow.component.grid.AbstractGridSingleSelectionModel.selectFromClient(AbstractGridSingleSelectionModel.java:66)
at com.vaadin.flow.component.grid.Grid.select(Grid.java:2748)
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.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:167)
at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.invokeMethod(PublishedServerEventHandlerRpcHandler.java:129)
at com.vaadin.flow.server.communication.rpc.PublishedServerEventHandlerRpcHandler.handleNode(PublishedServerEventHandlerRpcHandler.java:117)
at com.vaadin.flow.server.communication.rpc.AbstractRpcInvocationHandler.handle(AbstractRpcInvocationHandler.java:64)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocationData(ServerRpcHandler.java:387)
at com.vaadin.flow.server.communication.ServerRpcHandler.lambda$handleInvocations$1(ServerRpcHandler.java:368)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:368)
at com.vaadin.flow.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:310)
at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:89)
at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1507)
at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:242)
at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:352)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.springframework.web.servlet.mvc.ServletForwardingController.handleRequestInternal(ServletForwardingController.java:141)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:155)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:52)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
There’s probably a better way to work around this, but I ended up finding a fix that works. I’m thinking that the issue is that at some point in the view being created the result of e.getValue().getId() is calculated for all the items in the deviceGrid, and at another point the deviceList is rebuilt to account for the now checked out device which shouldn’t be in the list, and that happens in an order that results in a null for getValue() during the page load that is then fixed by deviceList being repopulated. I tried the ignoreValueChange solution but that didn’t get around the issue.
What I’ve tried was to implement BeforeLeaveObserver and then clear the items in the grid with a deviceGrid.setItems(new ArrayList<>()) in beforeLeave. That solved the problem in the UserDetails view, but now the same error comes up when navigating to DeviceDetails view with the same fixed on a refresh behavior.
This feels kind of ridiculous for how simple of a fix it is, but I finally solved it by moving deviceGrid.setItems(deviceList); into the constructor. So, it’s being set to a new ArrayList<>() at first, then in afterNavigation the deviceList is set to the list of items owned by the user. This is probably how things should have been from the start and I think was my core error.