Xpp3Dom.removeChild(int) (line 262-266) removes a child by index from childList, but then calls childMap.values().remove(child) to remove it from the map. This has two problems:
childMap.values().remove(child) removes the first matching value by object identity, which may be a different child than the one removed from childList when multiple children share the same name.
- The map entry key (child name) is never removed, so
getChild(name) may still return a stale or incorrect child.
Fix: use childMap.remove(child.getName(), child) which atomically removes the entry only when both the key and value match (available since Java 8).
Xpp3Dom.removeChild(int)(line 262-266) removes a child by index fromchildList, but then callschildMap.values().remove(child)to remove it from the map. This has two problems:childMap.values().remove(child)removes the first matching value by object identity, which may be a different child than the one removed fromchildListwhen multiple children share the same name.getChild(name)may still return a stale or incorrect child.Fix: use
childMap.remove(child.getName(), child)which atomically removes the entry only when both the key and value match (available since Java 8).