Skip to content
Snippets Groups Projects
Commit 839c1727 authored by srosse's avatar srosse
Browse files

OO-1381: hardened the insert method to prevent index bigger than the real size of the children list

parent dffd9dce
No related branches found
No related tags found
No related merge requests found
......@@ -124,15 +124,19 @@ public abstract class GenericNode implements INode, Serializable {
}
}
/**
* @see org.olat.core.util.nodes.INode#insert(org.olat.core.util.nodes.INode, int)
*/
@Override
public void insert(INode newChild, int index) {
if (isNodeAncestor(newChild)) throw new IllegalArgumentException("new child is an ancestor");
newChild.removeFromParent();
newChild.setParent(this);
if (children == null) children = new ArrayList<INode>(INITIAL_CHILD_SIZE);
children.add(index, newChild);
if (children == null) {
children = new ArrayList<INode>(INITIAL_CHILD_SIZE);
}
if(index > children.size()) {
children.add(newChild);
} else {
children.add(index, newChild);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment