From: Henri Sara Date: Tue, 30 May 2017 09:38:31 +0000 (+0300) Subject: Make TreeData.getChildren() return value immutable (#9455) X-Git-Tag: 8.1.0.beta2~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2b9bcc62cfa0ee1d4f5da915190a8f03f076037c;p=vaadin-framework.git Make TreeData.getChildren() return value immutable (#9455) This prevents unsupported modifications such as iterator.remove(). Closes #9446 --- diff --git a/server/src/main/java/com/vaadin/data/TreeData.java b/server/src/main/java/com/vaadin/data/TreeData.java index 7f6cc095bc..b0bdcde835 100644 --- a/server/src/main/java/com/vaadin/data/TreeData.java +++ b/server/src/main/java/com/vaadin/data/TreeData.java @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -340,7 +341,7 @@ public class TreeData implements Serializable { /** * Gets the root items of this structure. * - * @return the root items of this structure + * @return an unmodifiable list of root items of this structure */ public List getRootItems() { return getChildren(null); @@ -352,7 +353,7 @@ public class TreeData implements Serializable { * @param item * the item for which to retrieve child items for, null to * retrieve all root items - * @return a list of child items for the given item + * @return an unmodifiable list of child items for the given item * * @throws IllegalArgumentException * if the item does not exist in this structure @@ -362,7 +363,8 @@ public class TreeData implements Serializable { throw new IllegalArgumentException( "Item '" + item + "' not in the hierarchy"); } - return itemToWrapperMap.get(item).getChildren(); + return Collections + .unmodifiableList(itemToWrapperMap.get(item).getChildren()); } /**