diff options
author | Henri Sara <hesara@vaadin.com> | 2015-04-16 09:19:16 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-04-16 10:11:34 +0000 |
commit | ab8a0268652b81b20be8d5dbf0deeb7029e9edec (patch) | |
tree | 191a88d23e348beab04ff12bbd374a2a8b10c787 /server | |
parent | 8ecdcd9d665acc7e6423aa9493a4302dfb266be2 (diff) | |
download | vaadin-framework-ab8a0268652b81b20be8d5dbf0deeb7029e9edec.tar.gz vaadin-framework-ab8a0268652b81b20be8d5dbf0deeb7029e9edec.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); } } |