java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.server.VaadinSession.getState()"

Hi there!
Does anyone know why this error occurs?
message.txt (13.7 KB)

Session expired :thinking: But it certainly shouldn’t throw an exception like that. Any other details about the situation where it happens. Which Vaadin version?

Vaadin version <vaadin.version>14.9.4</vaadin.version>
I’ve checked one of previous version 14.8.11. - the issue occurs too. It happens in very different situations, which is hard to investigate.
The stack trace does not tell much.
On the prod environment of course this happens in different way, but locally I’m replicating this by scenario:

We have selenium automatic tests and
I’m using one of them.

  1. Log in to the app.
  2. Go to the view with form.
  3. Fill the form which is custom stepper.
  4. Click next.
  5. Then another view is being initialized. (Navigating)
  6. There is @PostConsuct method where there is view initialization - adding components to the view. (Not sure, but maybe this is the cause. Maybe view initialization should be done in attach Listener - there are also calls to the API)
  7. I’m having there a breakpoint in the IDE.
  8. App stops on the breakpoint
  9. After few seconds when I release the breakpoint and the app runs again.
  10. The exception is thrown and is logged by session error handler
    (Implementation of ErrorHandler interface).

@quintessential-ibex

When Thread stops

   try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

Then vaadin creates a new session and destroys the first one, why? Then the thread looses, the authentication from SecurityContextHolder.getContext().getAuthentication() is null .