“Can't move a node from one state tree to another” error in Vaadin 10

Hello everyone,

I’m using Vaadin for a while now. This year I migrated a project from Vaadin 7 to Vaadin 10 with Spring boot.

I want to use the @Push feature on my views. For now, it’s fully working, but sometimes (in my opinion, it happens randomly, but I don’t want to believe that) the app crashes with the following error: java.lang.IllegalStateException: Can't move a node from one state tree to another. After this, when it happens once, the next queries and interface updates will throw this error (for any user of the application). The good news is that the application will execute the query even if the user won’t receive the successful feedback.
If the user reload the page, he can do usually one query before the error shows up again.

My views are annotated with @UIScope and @SpringComponent for the majority of them. I don’t know if I use well the UI.getCurrent().access() method. Maybe I’m missing something around this feature.

The full stack trace:

com.vaadin.flow.server.DefaultErrorHandler error
SEVERE: 
java.lang.IllegalStateException: Can't move a node from one state tree to another
    at com.vaadin.flow.internal.StateNode.doSetTree(StateNode.java:474)
    at com.vaadin.flow.internal.StateNode.lambda$setTree$2(StateNode.java:266)
    at com.vaadin.flow.internal.StateNode.visitNodeTree(StateNode.java:433)
    at com.vaadin.flow.internal.StateNode.setTree(StateNode.java:266)
    at com.vaadin.flow.internal.StateNode.setParent(StateNode.java:198)
    at com.vaadin.flow.internal.nodefeature.NodeFeature.attachPotentialChild(NodeFeature.java:78)
    at com.vaadin.flow.internal.nodefeature.StateNodeNodeList.add(StateNodeNodeList.java:53)
    at com.vaadin.flow.internal.nodefeature.ElementChildrenList.add(ElementChildrenList.java:42)
    at com.vaadin.flow.dom.impl.AbstractNodeStateProvider.insertChild(AbstractNodeStateProvider.java:92)
    at com.vaadin.flow.dom.Node.insertChild(Node.java:247)
    at com.vaadin.flow.dom.Node.appendChild(Node.java:141)
    at com.vaadin.flow.component.HasComponents.add(HasComponents.java:50)
    at com.vaadin.flow.component.UI.add(UI.java:839)
    at com.vaadin.flow.component.notification.Notification.lambda$setOpened$63d2899d$1(Notification.java:396)
    at com.vaadin.flow.internal.StateTree.lambda$runExecutionsBeforeClientResponse$1(StateTree.java:350)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at com.vaadin.flow.internal.StateTree.runExecutionsBeforeClientResponse(StateTree.java:347)
    at com.vaadin.flow.server.communication.UidlWriter.encodeChanges(UidlWriter.java:334)
    at com.vaadin.flow.server.communication.UidlWriter.createUidl(UidlWriter.java:179)
    at com.vaadin.flow.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:119)
    at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
    at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
    at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1486)
    at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:300)
    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:998)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
    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.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:66)
    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:199)
    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:770)
    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)

I created [a StackOverflow question]
(https://stackoverflow.com/questions/53477572/cant-move-a-node-from-one-state-tree-to-another-error-in-vaadin-10) describing the same issue but I think this belongs better here.

If you have any idea or just direction to follow I’ll be thankful :slight_smile:

Paul Rey:
Hello everyone,

I’m using Vaadin for a while now. This year I migrated a project from Vaadin 7 to Vaadin 10 with Spring boot.

I want to use the @Push feature on my views. For now, it’s fully working, but sometimes (in my opinion, it happens randomly, but I don’t want to believe that) the app crashes with the following error: java.lang.IllegalStateException: Can't move a node from one state tree to another. After this, when it happens once, the next queries and interface updates will throw this error (for any user of the application). The good news is that the application will execute the query even if the user won’t receive the successful feedback.
If the user reload the page, he can do usually one query before the error shows up again.

My views are annotated with @UIScope and @SpringComponent for the majority of them. I don’t know if I use well the UI.getCurrent().access() method. Maybe I’m missing something around this feature.

The full stack trace:

com.vaadin.flow.server.DefaultErrorHandler error
SEVERE: 
java.lang.IllegalStateException: Can't move a node from one state tree to another
    at com.vaadin.flow.internal.StateNode.doSetTree(StateNode.java:474)
    at com.vaadin.flow.internal.StateNode.lambda$setTree$2(StateNode.java:266)
    at com.vaadin.flow.internal.StateNode.visitNodeTree(StateNode.java:433)
    at com.vaadin.flow.internal.StateNode.setTree(StateNode.java:266)
    at com.vaadin.flow.internal.StateNode.setParent(StateNode.java:198)
    at com.vaadin.flow.internal.nodefeature.NodeFeature.attachPotentialChild(NodeFeature.java:78)
    at com.vaadin.flow.internal.nodefeature.StateNodeNodeList.add(StateNodeNodeList.java:53)
    at com.vaadin.flow.internal.nodefeature.ElementChildrenList.add(ElementChildrenList.java:42)
    at com.vaadin.flow.dom.impl.AbstractNodeStateProvider.insertChild(AbstractNodeStateProvider.java:92)
    at com.vaadin.flow.dom.Node.insertChild(Node.java:247)
    at com.vaadin.flow.dom.Node.appendChild(Node.java:141)
    at com.vaadin.flow.component.HasComponents.add(HasComponents.java:50)
    at com.vaadin.flow.component.UI.add(UI.java:839)
    at com.vaadin.flow.component.notification.Notification.lambda$setOpened$63d2899d$1(Notification.java:396)
    at com.vaadin.flow.internal.StateTree.lambda$runExecutionsBeforeClientResponse$1(StateTree.java:350)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at com.vaadin.flow.internal.StateTree.runExecutionsBeforeClientResponse(StateTree.java:347)
    at com.vaadin.flow.server.communication.UidlWriter.encodeChanges(UidlWriter.java:334)
    at com.vaadin.flow.server.communication.UidlWriter.createUidl(UidlWriter.java:179)
    at com.vaadin.flow.server.communication.UidlRequestHandler.writeUidl(UidlRequestHandler.java:119)
    at com.vaadin.flow.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
    at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
    at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1486)
    at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:300)
    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:998)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
    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.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:66)
    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:199)
    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:770)
    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)

I created [a StackOverflow question]
(https://stackoverflow.com/questions/53477572/cant-move-a-node-from-one-state-tree-to-another-error-in-vaadin-10) describing the same issue but I think this belongs better here.

If you have any idea or just direction to follow I’ll be thankful :slight_smile:

Hi! I’ve just had this issue today, and the reason in my case was inconsistent bean scopes across my application.
More precisely I had a UIScoped vaadin component which held another singleton (default) scoped component. Once I adjusted the scopes in the right manner the exception disappeared.

Thank you for the advice, I think I used to many times and wrongly the annotation @UIScope.
When you say:

[…]
singleton (default) scoped component […]

Do you mean you’re using a different @Scope configuration?

I would like to know, I you don’t mind, what component do you annotate with @UIScope. For now, I only have the views. Before I had some Notification, Dialog, Grid and others Vaadin components annotated with it.

And do you know if I have a Spring component “autowired” in a parent Vaadin component and if I give this Spring component to an instance of a child Vaadin component. Will I have issues?

I had the same problem and I found out that I had an extra SpringComponent annotation on my view class. When I removed it the problem was solved.

I had this happen to me when i accidentially added the same component twice, eg.

  TextField tf = new TextField();
  layout.add(tf);
  ...
  // adding other components
  ...
  if (monday)
    layout.add(tf);

Hi!
I had the similar problem:
Can’t move a node from one state tree to another. If this is intentional, first remove the node from its current state tree by calling removeFromTree.
I added @VaadinSessionScope on the class which had @SpringComponent annotation and it solved my issue.
Check this article:
https://vaadin.com/docs/flow/spring/tutorial-spring-scopes.html

UPDATE:

In my case it was helpful when the @SpringComponent scope was set to prototype: @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE).

Martin Israelsen:
I had this happen to me when i accidentially added the same component twice, eg.

  TextField tf = new TextField();
  layout.add(tf);
  ...
  // adding other components
  ...
  if (monday)
    layout.add(tf);

How to troubleshoot this scnario? I mean is there a way to find the offending duplicate? I am having this same exact exception and stacktrace with 14.2.0… a few minutes later, the CPU spins up and I see out of heap error on the vaadin server logs… so in my case, I do not know what is the offender but somehow must be identified and fixed.

Maybe 14.2.1 helps:

https://github.com/vaadin/platform/releases/tag/14.2.1

“Fix for “Error “Can’t move a node from one state tree to another.” when re-adding a previously removed component after refreshing with @PreserveOnRefresh” (#8286)”

Maybe not the exact error you had but maybe the checkin solved your problems too?

Me too getting the same error “java.lang.IllegalStateException: Can’t move a node from one state tree to another. If this is intentional, first remove the node from its current state tree by calling removeFromTree” but randomly.

If I refresh the page or edit some components values, I get this error. Any help pls?

Looks it is due the same reason @Sathya had mentioned above. If you add a component, twice and refresh the page, you would get this error.

I have been drilling more on this error. Just to let you know, this problem has not gone… I am describing my observations and confirmations here, hoping there would be a bug-fix soon enough.

  • The issue is not related to @PreserveOnRefresh. I get the same stacktrace (in my case, it is related to using navigate() invoked through getUI().get().navigate(MyView.class); regardless of whether I use the annotation or not.
  • The issue occurs only when the navigation is requested as above, or direct URL is used after a view is rendered on the bowser. The direct URL case can any of the following scenarios:
    • Refreshing the browser
    • Using a URL (that the Router recognises from the registry) on the URL bar in the browser.
    • Accessing the application or any of its URLs from a new tab/ window in the browser, when the same instance of server is running.
  • The issue does not occur when setting up user-triggered navigation through RouterLink but when anchors with href (using relative urls) are used (such as BreadCrumbs component) this exception throws up guaranteed.
  • I have eliminated the scenarios on SpringComponent described on the forums. I use only SpringComponent to distinguish between vaadin and spring component. Also, I have ensured that faceless (only functional logic made available as a utilitarian class) bean is always annotated with @VaadinSessionScope. This is meant to ensure any cached info is consistent and provides integrity to the cache across the application.
  • I have also ensured that all components created in my view classes are not added again inadvertantly.
  • Additionally, I have setup @PostConstruct and @PreDestroy to hook into the bean lifecycle of all my UI View classes. I explicitly call removeRouterLayoutContent(this); because all my view pages are instances of AppLayout which implements RouterLayout and I see router component suffering some bug in the stacktrace for this issue.

Finally, after all the above, I see the new navigation target being rendered now. But the exception occurs and the stacktrace printed on the server side. After a few mins, the CPU utilization sky-rockets and I start seeing OutOfMemoryError. Obviously, this is a clear evidence of an ininite loop with memory alloc inside.

I have almost reaching the boundaries of what I can control/ influence to progress further. I hope someone from Vaadin reads though this and help provide a bug fix for this error.

Vaadin also doesn’t support storing components in static fields. In my case that was the issue. (Vaadin 18).

I just experienced this Exception.
I had two home made UI components as Spring @Component each with their own @Autowiring of dependencies. Then I injected them into a Vaadin View class. It worked with a fresh Spring Container but then the Exception occured.

Solution: I skipped springifying this two component classes and provided the dependency via their constructor and instansiated the classes myself. The Exception is gone.

Andor Németh:
Hi!
I had the similar problem:
Can’t move a node from one state tree to another. If this is intentional, first remove the node from its current state tree by calling removeFromTree.
I added @VaadinSessionScope on the class which had @SpringComponent annotation and it solved my issue.
Check this article:
https://vaadin.com/docs/flow/spring/tutorial-spring-scopes.html

UPDATE:

In my case it was helpful when the @SpringComponent scope was set to prototype: @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE).

That was very helpful. After add @UIScope to my @SpringComponent class, @CssImport doesn’t load after change view. This solved my issue.
Thanks :slight_smile:

The root of the problem is that moving a component from one UI to another causes the component to silently disappear in the former UI, thus causing a hard-to-reproduce strange behavior. This exception was designed to prevent that, but the message was just horrible. Hopefully this PR improves things: https://github.com/vaadin/flow/pull/18019