fix: resolve route scope UI from the detach event (CP: 24.10) - #25069
Merged
Conversation
RouteStoreWrapper#getBeanStore re-points a bean store to the UI created by a browser refresh, but the store's detach listener stays on the previous UI. resetUI() then asked findPreservingUI() about currentUI, which is no longer the UI the detach event comes from. If the refreshed UI had already been removed from the session, its session reference is null and findPreservingUI() threw a NullPointerException. The exception escaped before the branch that destroys the store, so the route scoped beans were not destroyed and the store stayed in routeStores. During session expiration the beans are still released by the session destroy listener of RouteStoreWrapper, but when only the UIs of an idle browser window are removed nothing cleans them up and they leak until the session ends. Pass the detached UI from the event into resetUI() so the lookup always gets the UI the event originates from, which still has its session at that point. findPreservingUI() now also returns null instead of dereferencing a UI that has no session anymore. Fixes #25027
mockSession() sets the current VaadinSession in a thread local that nothing cleared once the test had finished. Surefire reuses the JVM and its threads across test classes, so the stale session stayed visible to unrelated tests. VaadinSessionScopeTest extends AbstractScopeTest directly and therefore has no setup clearing the thread local, while inheriting tests that assert an exception is thrown when no session is current. Those tests passed only because of the order the test methods happened to run in.
Contributor
caalador
approved these changes
Jul 30, 2026
vaadin-bot
added a commit
that referenced
this pull request
Jul 30, 2026
… (CP: 24.9) (#25072) This PR cherry-picks changes from the original PR #25069 to branch 24.9. --- #### Original PR description > This PR cherry-picks changes from the original PR #25064 to branch 24.10. > --- > #### Original PR description > > RouteStoreWrapper#getBeanStore re-points a bean store to the UI created by a > > browser refresh, but the store's detach listener stays on the previous UI. > > resetUI() then asked findPreservingUI() about currentUI, which is no longer > > the UI the detach event comes from. > > > > If the refreshed UI had already been removed from the session, its session > > reference is null and findPreservingUI() threw a NullPointerException. The > > exception escaped before the branch that destroys the store, so the route > > scoped beans were not destroyed and the store stayed in routeStores. During > > session expiration the beans are still released by the session destroy > > listener of RouteStoreWrapper, but when only the UIs of an idle browser > > window are removed nothing cleans them up and they leak until the session > > ends. > > > > Pass the detached UI from the event into resetUI() so the lookup always gets > > the UI the event originates from, which still has its session at that point. > > findPreservingUI() now also returns null instead of dereferencing a UI that > > has no session anymore. > > > > Fixes #25027 Co-authored-by: Marco Collovati <marco@vaadin.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR cherry-picks changes from the original PR #25064 to branch 24.10.
Original PR description