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.
This commit is contained in:
parent
c23f28b51c
commit
c73fd99dd6
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user