Prevent accidental mutation of Elements
Stephen Paul Weber
created
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
Change summary
src/main/java/eu/siacs/conversations/xml/Element.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Detailed changes
@@ -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<Element> getChildren() {
- return this.children;
+ return ImmutableList.copyOf(this.children);
}
// Deprecated: you probably want bindTo or replaceChildren
public Element setChildren(List<Element> children) {
this.childNodes = new ArrayList(children);
- this.children = children;
+ this.children = new ArrayList(children);
return this;
}