diff options
author | Henri Sara <hesara@vaadin.com> | 2015-04-16 09:19:16 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-04-27 13:18:22 +0300 |
commit | 6e46ed68d6cae41cb63560be9fa3ddd23bcf2e2f (patch) | |
tree | 7218936671851e5848e2592b61d9f9f0205b5428 /server | |
parent | f8404b9be9d8f599ae62d0be22aab3e25142796f (diff) | |
download | vaadin-framework-6e46ed68d6cae41cb63560be9fa3ddd23bcf2e2f.tar.gz vaadin-framework-6e46ed68d6cae41cb63560be9fa3ddd23bcf2e2f.zip |
Iterate over copies of listener lists (#17477)
Allows adding/removing view change listeners from listeners.
Change-Id: Idb2227e1423c0297887f01f6df03b74e633ad917
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/navigator/Navigator.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index ef5c61a294..65b3fec488 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -32,6 +32,7 @@ package com.vaadin.navigator; */ import java.io.Serializable; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -597,7 +598,10 @@ public class Navigator implements Serializable { * block the navigation operation */ protected boolean fireBeforeViewChange(ViewChangeEvent event) { - for (ViewChangeListener l : listeners) { + // a copy of the listener list is needed to avoid + // ConcurrentModificationException as a listener can add/remove + // listeners + for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) { if (!l.beforeViewChange(event)) { return false; } @@ -647,7 +651,10 @@ public class Navigator implements Serializable { * view change event (not null) */ protected void fireAfterViewChange(ViewChangeEvent event) { - for (ViewChangeListener l : listeners) { + // a copy of the listener list is needed to avoid + // ConcurrentModificationException as a listener can add/remove + // listeners + for (ViewChangeListener l : new ArrayList<ViewChangeListener>(listeners)) { l.afterViewChange(event); } } |