From 3860c9c63d1273a45da264a463c38f2e1209b8bb Mon Sep 17 00:00:00 2001 From: mkpaz Date: Tue, 30 May 2023 16:00:46 +0400 Subject: [PATCH] Fix NPE when the Popover owner is not added to the scene #49 --- base/src/main/java/atlantafx/base/controls/Popover.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/atlantafx/base/controls/Popover.java b/base/src/main/java/atlantafx/base/controls/Popover.java index f745128..31c2e39 100755 --- a/base/src/main/java/atlantafx/base/controls/Popover.java +++ b/base/src/main/java/atlantafx/base/controls/Popover.java @@ -29,7 +29,6 @@ package atlantafx.base.controls; -import static java.util.Objects.requireNonNull; import static javafx.scene.input.MouseEvent.MOUSE_CLICKED; import java.util.Objects; @@ -252,9 +251,14 @@ public class Popover extends PopupControl { * overlap with the owner node (positive values are recommended) */ public final void show(Node owner, double offset) { - requireNonNull(owner); + Objects.requireNonNull(owner, "Owner node cannot be null!"); Bounds bounds = owner.localToScreen(owner.getBoundsInLocal()); + if (bounds == null) { + throw new IllegalStateException( + "The owner node is not added to the scene. It cannot be used as a popover anchor." + ); + } switch (getArrowLocation()) { case BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT -> show(