]> source.dussan.org Git - vaadin-framework.git/commitdiff
Make TreeData.getChildren() return value immutable (#9455)
authorHenri Sara <henri.sara@gmail.com>
Tue, 30 May 2017 09:38:31 +0000 (12:38 +0300)
committerGitHub <noreply@github.com>
Tue, 30 May 2017 09:38:31 +0000 (12:38 +0300)
This prevents unsupported modifications such as iterator.remove().

Closes #9446

server/src/main/java/com/vaadin/data/TreeData.java

index 7f6cc095bc820d73fe19e5cdd9205025b5b3d9ea..b0bdcde8359ecb2c4bc0768d73300ec8c4191837 100644 (file)
@@ -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<T> 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<T> getRootItems() {
         return getChildren(null);
@@ -352,7 +353,7 @@ public class TreeData<T> 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<T> implements Serializable {
             throw new IllegalArgumentException(
                     "Item '" + item + "' not in the hierarchy");
         }
-        return itemToWrapperMap.get(item).getChildren();
+        return Collections
+                .unmodifiableList(itemToWrapperMap.get(item).getChildren());
     }
 
     /**