From 5e414dd7b99ebc8cb6c17e6d99beb62190d2725d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 13 Dec 2022 01:39:03 -0500 Subject: [PATCH] Prevent accidental mutation of Elements If you want to mutate, use bindTo and mutate the Element, don't getChildren() and mutate that or it will get out of sync with childNodes --- src/main/java/eu/siacs/conversations/xml/Element.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index 0b572a64318d191cff15d2e5a25ca234f97c233c..269cd3aaaa410b7759a31e23cb7df9385574c69a 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.xml; import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; import com.google.common.primitives.Ints; import org.jetbrains.annotations.NotNull; @@ -134,13 +135,13 @@ public class Element implements Node { } public final List getChildren() { - return this.children; + return ImmutableList.copyOf(this.children); } // Deprecated: you probably want bindTo or replaceChildren public Element setChildren(List children) { this.childNodes = new ArrayList(children); - this.children = children; + this.children = new ArrayList(children); return this; }