From c73fd99dd6b93f94fe7e16ac917b7faeeb7a96ad Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Thu, 28 Nov 2019 15:56:15 -0500 Subject: [PATCH] Fixed the null child check to throw IllegalArgumentException instead of NullPointerException because user code should never throw NullPointerException. Also made trying to add a child to itself an error instead of a no-op. Attempting to do something like guiNode.attachChild(guiNode) will now throw an IllegalArgumentException. --- jme3-core/src/main/java/com/jme3/scene/Node.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/scene/Node.java b/jme3-core/src/main/java/com/jme3/scene/Node.java index ef3ed34b8..d16246d2d 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Node.java +++ b/jme3-core/src/main/java/com/jme3/scene/Node.java @@ -345,10 +345,13 @@ public class Node extends Spatial { * @throws NullPointerException if child is null. */ public int attachChildAt(Spatial child, int index) { - if (child == null) - throw new NullPointerException(); - - if (child.getParent() != this && child != this) { + if (child == null) { + throw new IllegalArgumentException("child cannot be null"); + } + if (child == this) { + throw new IllegalArgumentException("Cannot add child to itself"); + } + if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); }