Skip to content

Commit 727ecee

Browse files
committed
safety checks on child insertion
1 parent e0be9d3 commit 727ecee

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • src/main/java/org/variantsync/diffdetective/diff/difftree

src/main/java/org/variantsync/diffdetective/diff/difftree/DiffNode.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ public boolean insertAfterChild(final DiffNode child, int index) {
335335

336336
public boolean addBeforeChild(final DiffNode child) {
337337
if (!child.isAdd()) {
338+
if (child.beforeParent != null) {
339+
throw new IllegalArgumentException("Given child " + child + " already has a before parent (" + child.beforeParent + ")!");
340+
}
341+
338342
addWithoutDuplicates(beforeChildren, child);
339343
addWithoutDuplicates(childOrder, child);
340344
child.setBeforeParent(this);
@@ -345,6 +349,10 @@ public boolean addBeforeChild(final DiffNode child) {
345349

346350
public boolean addAfterChild(final DiffNode child) {
347351
if (!child.isRem()) {
352+
if (child.afterParent != null) {
353+
throw new IllegalArgumentException("Given child " + child + " already has an after parent (" + child.afterParent + ")!");
354+
}
355+
348356
addWithoutDuplicates(afterChildren, child);
349357
addWithoutDuplicates(childOrder, child);
350358
child.setAfterParent(this);

0 commit comments

Comments
 (0)