Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,22 @@ public int getChildCount() {
*/
public void removeChild(int i) {
Xpp3Dom child = childList.remove(i);
childMap.values().remove(child);
child.setParent(null);

String name = child.getName();
if (childMap.get(name) == child) {
Xpp3Dom lastWithName = null;
for (Xpp3Dom c : childList) {
if (name.equals(c.getName())) {
lastWithName = c;
}
}
if (lastWithName != null) {
childMap.put(name, lastWithName);
} else {
childMap.remove(name);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ private Xpp3Dom createElement(String element, String value) {
return t1s1;
}

@Test
public void removeChildByIndexUpdatesChildMap() {
Xpp3Dom parent = new Xpp3Dom("parent");
Xpp3Dom first = new Xpp3Dom("child");
first.setValue("first");
Xpp3Dom second = new Xpp3Dom("child");
second.setValue("second");
parent.addChild(first);
parent.addChild(second);

parent.removeChild(1);

assertEquals(1, parent.getChildCount());
assertEquals("first", parent.getChild("child").getValue());
}

@Test
public void mergePrecedenceSelfClosed() throws XmlPullParserException {
Xpp3Dom parentConfig = build("<configuration><items><item/></items></configuration>");
Expand Down
Loading