diff --git a/core/math/src/main/java/org/arakhne/afc/math/tree/node/NaryTreeNode.java b/core/math/src/main/java/org/arakhne/afc/math/tree/node/NaryTreeNode.java index bc052c6e9..33ba22543 100644 --- a/core/math/src/main/java/org/arakhne/afc/math/tree/node/NaryTreeNode.java +++ b/core/math/src/main/java/org/arakhne/afc/math/tree/node/NaryTreeNode.java @@ -239,7 +239,7 @@ public boolean setChildAt(int index, N newChild) throws IndexOutOfBoundsExceptio throw new IndexOutOfBoundsException(); } - final N oldChild = (index < count) ? this.children.get(index) : null; + final N oldChild = this.children.get(index); if (oldChild == newChild) { return false; } @@ -257,19 +257,11 @@ public boolean setChildAt(int index, N newChild) throws IndexOutOfBoundsExceptio } } - if (index < count) { - // set the element - if (newChild != null) { - this.children.set(index, newChild); - } else { - this.children.remove(index); - } - } else if (newChild != null) { - // Resize the array - if (this.children == null) { - this.children = newInternalList(index + 1); - } - this.children.add(newChild); + // set the element + if (newChild != null) { + this.children.set(index, newChild); + } else { + this.children.remove(index); } if (newChild != null) {