Skip to content

Xpp3Dom.removeChild(int) corrupts childMap on duplicate names #394

Description

@elharo

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:

  1. 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.
  2. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions