"Cannot remove from parent when the session is not locked ..."

My Vaadin Spring Boot App is deployed to a server and runs fine as long as I don’t open the app in two different browsers (e.g. Chrome and Safari) …

When I open the app from a second (different) browser, I’m getting this error message:

“Cannot remove from parent when the session is not locked . Furthermore, there is another locked session, indicating that the component might be about to be moved from one session to another.”

I read that this error occurs when you define UI components statically … but I did not do that with any of my UI components.

What might cause this exception?

maybe you have a component that is not UI or View scoped.
Do you have ui components marked as @Component instead of @SpringComponent?

Thank you for your help.

The file GUI.java contains the code with the line throwing the error.
I indicated the line through a comment.

It seems like adding the menuBar to the GUI (in a second browser) causes the problem.

The file MenuBarFactory.java contains the code for creating a MenuBar.

The views are displayed inside the “viewContainer” (see line 34 in GUI.java).

Each view has the following annotations (here shown for “DefaultView”):

@SpringView(name=DefaultView.NAME, ui= GUI.class)
public class DefaultView extends VerticalLayout implements View {



The MenuBarFactory is a SpringComponent (i.e. annotation is @SpringComponent), the menuBar is a Vaadin-UI-Component.

Is there something wrong with this code? If so, why?

37904.java (1.32 KB)
37905.java (1.15 KB)

I think you have to specify @UIScope also for MenuBarFactory otherwise it will have singleton scope and it will be shared across all UIs


Hi Marco,

Thank you very much for your answer.

I annotated the menubar-factory with “@UIScope” … the old error (“Cannot remove from parent when the session is not locked …”) does not show up any more.

However, another kind of error still shows up after switching between views several times (the specific id, in this case: 94, varies):

“java.lang.RuntimeException: A connector with id 94 is already registered!”

The error occurs when the navigator wants to switch to some view, i.e. in file MenuBarFactory, inside the function “switchViewTo” at the line


Do you also know why this error occurs?

I have one idea: each of the views has the following structure:

@PostConstruct void init() {


The Grid components are annotated with “@SpringComponent” … Maybe they also have to be annotated with “@UIScope?”

… I will try that out …

… ok, it seems to work fine now … thank you very much for your help !

I think that the components that you inject into views may be marked as @ViewScope, so their lifecycle is bounded to the lifecycle of the single view.

Best regards