aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@gmail.com>2017-05-26 15:32:32 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-05-26 15:32:32 +0300
commitf71f751852ca8136af68853058d835def87db429 (patch)
tree533a086fdb50fae13b846a05e4f1cf70c2876659
parentd7fd3022bb286392f5bd4223860ee1facbd84b62 (diff)
downloadvaadin-framework-f71f751852ca8136af68853058d835def87db429.tar.gz
vaadin-framework-f71f751852ca8136af68853058d835def87db429.zip
Make component iterators unmodifiable
Fixes #9404
-rw-r--r--server/src/main/java/com/vaadin/ui/AbsoluteLayout.java5
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java9
-rw-r--r--server/src/main/java/com/vaadin/ui/CssLayout.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/CustomLayout.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/HasComponents.java3
-rw-r--r--server/src/main/java/com/vaadin/ui/UI.java2
7 files changed, 19 insertions, 9 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
index 0fc5ee82c2..beedc52a45 100644
--- a/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
+++ b/server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
@@ -16,6 +16,7 @@
package com.vaadin.ui;
import java.io.Serializable;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -85,7 +86,9 @@ public class AbsoluteLayout extends AbstractLayout
*/
@Override
public Iterator<Component> iterator() {
- return componentToCoordinates.keySet().iterator();
+ return Collections
+ .unmodifiableCollection(componentToCoordinates.keySet())
+ .iterator();
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
index 75cea826c0..a90f8e8d8a 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
@@ -17,6 +17,7 @@
package com.vaadin.ui;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Logger;
@@ -184,7 +185,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout
*/
@Override
public Iterator<Component> iterator() {
- return components.iterator();
+ return Collections.unmodifiableCollection(components).iterator();
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java b/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
index f518b2ba5c..93afdcfc2a 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSplitPanel.java
@@ -226,12 +226,13 @@ public abstract class AbstractSplitPanel extends AbstractComponentContainer {
}
}
- /*
- * (non-Javadoc)
+ /**
+ * Gets an iterator to the collection of contained components. Using this
+ * iterator it is possible to step through all components contained in this
+ * container and remove components from it.
*
- * @see com.vaadin.ui.ComponentContainer#getComponentIterator()
+ * @return the component iterator.
*/
-
@Override
public Iterator<Component> iterator() {
return new ComponentIterator();
diff --git a/server/src/main/java/com/vaadin/ui/CssLayout.java b/server/src/main/java/com/vaadin/ui/CssLayout.java
index d293dbe47c..a407859d08 100644
--- a/server/src/main/java/com/vaadin/ui/CssLayout.java
+++ b/server/src/main/java/com/vaadin/ui/CssLayout.java
@@ -15,6 +15,7 @@
*/
package com.vaadin.ui;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
@@ -194,7 +195,7 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier {
*/
@Override
public Iterator<Component> iterator() {
- return components.iterator();
+ return Collections.unmodifiableCollection(components).iterator();
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/CustomLayout.java b/server/src/main/java/com/vaadin/ui/CustomLayout.java
index b2eb675c56..0293b0a648 100644
--- a/server/src/main/java/com/vaadin/ui/CustomLayout.java
+++ b/server/src/main/java/com/vaadin/ui/CustomLayout.java
@@ -20,6 +20,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -205,7 +206,7 @@ public class CustomLayout extends AbstractLayout implements LegacyComponent {
*/
@Override
public Iterator<Component> iterator() {
- return slots.values().iterator();
+ return Collections.unmodifiableCollection(slots.values()).iterator();
}
/**
diff --git a/server/src/main/java/com/vaadin/ui/HasComponents.java b/server/src/main/java/com/vaadin/ui/HasComponents.java
index 763f4b67cd..7d15dbd264 100644
--- a/server/src/main/java/com/vaadin/ui/HasComponents.java
+++ b/server/src/main/java/com/vaadin/ui/HasComponents.java
@@ -35,6 +35,9 @@ public interface HasComponents extends Component, Iterable<Component> {
* Gets an iterator to the collection of contained components. Using this
* iterator it is possible to step through all components contained in this
* container.
+ * <p>
+ * The iterator is typically unmodifiable, and calls to
+ * {@link Iterator#remove()} throw an exception.
*
* @return the component iterator.
*/
diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java
index ed2d58df3c..420e349305 100644
--- a/server/src/main/java/com/vaadin/ui/UI.java
+++ b/server/src/main/java/com/vaadin/ui/UI.java
@@ -467,7 +467,7 @@ public abstract class UI extends AbstractSingleComponentContainer
components.addAll(windows);
- return components.iterator();
+ return Collections.unmodifiableCollection(components).iterator();
}
/*