changeset 8007:887985e5611d

RT-38616: ConcurrentModificationException when SubScene.setUserAgentStylesheet() is called
author David Grieve<david.grieve@oracle.com>
date Tue, 16 Sep 2014 12:05:58 -0400
parents 55914cd82ec8
children ce204e7db505
files modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java	Tue Sep 16 17:43:48 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java	Tue Sep 16 12:05:58 2014 -0400
@@ -532,9 +532,10 @@
             }
         }
 
-        Iterator<StylesheetContainer> containerIterator = stylesheetContainerMap.values().iterator();
+        Iterator<Entry<String,StylesheetContainer>> containerIterator = stylesheetContainerMap.entrySet().iterator();
         while (containerIterator.hasNext()) {
-            StylesheetContainer container = containerIterator.next();
+            Entry<String,StylesheetContainer> entry = containerIterator.next();
+            StylesheetContainer container = entry.getValue();
             container.parentUsers.remove(parent);
             if (container.parentUsers.list.isEmpty()) {
 
@@ -620,13 +621,14 @@
         //
         // remove any parents belonging to this SubScene from the stylesheetContainerMap
         //
-        Set<Entry<String,StylesheetContainer>> stylesheetContainers = stylesheetContainerMap.entrySet();
-        Iterator<Entry<String,StylesheetContainer>> iter = stylesheetContainers.iterator();
+        // copy the list to avoid concurrent mod.
+        List<StylesheetContainer> stylesheetContainers = new ArrayList<>(stylesheetContainerMap.values());
+
+        Iterator<StylesheetContainer> iter = stylesheetContainers.iterator();
 
         while(iter.hasNext()) {
 
-            Entry<String,StylesheetContainer> entry = iter.next();
-            StylesheetContainer container = entry.getValue();
+            StylesheetContainer container = iter.next();
 
             Iterator<Reference<Parent>> parentIter = container.parentUsers.list.iterator();
             while (parentIter.hasNext()) {