Commit 76da373
fix: avoid NPE when popover target is set again during auto-add (#9912)
When `setTarget` is called with a target that is already attached, the
popover is auto-added to the UI right away. The auto-add fires the
popover's attach listeners, and if one of them calls `setTarget` again,
that call fails with a `NullPointerException`. This happens because the
first call assigns `targetAttachRegistration` and
`targetDetachRegistration` only after the auto-add, so the nested call
finds a non-null target but null registrations.
`setTarget` now assigns both registrations before running the initial
attach logic. Only adding null checks around the `remove()` calls would
also avoid the exception, but it would leak listeners: the nested call
would register its own listeners on the target, and the first call would
then overwrite them without removing them. The leaked detach listener
could later remove the popover from the UI even though its target had
already changed. A separate test covers this by detaching the first
target and checking that the popover stays in the UI.
Fixes #7758
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent cc15e58 commit 76da373
2 files changed
Lines changed: 38 additions & 1 deletion
File tree
- vaadin-popover-flow-parent/vaadin-popover-flow/src
- main/java/com/vaadin/flow/component/popover
- test/java/com/vaadin/flow/component/popover
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
750 | | - | |
751 | 750 | | |
752 | 751 | | |
753 | 752 | | |
754 | 753 | | |
755 | 754 | | |
| 755 | + | |
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
158 | 195 | | |
159 | 196 | | |
160 | 197 | | |
| |||
0 commit comments