changeset 4328:34fab9fcc574 8.0-b99

RT-31714 - make a copy of the entry set and clear the cssSetProperties immediately.
author David Grieve<david.grieve@oracle.com>
date Wed, 17 Jul 2013 12:16:33 -0400
parents 86380c7b3348
children aa1f69d49266 537ed8141418 57275a6c2544
files modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java
diffstat 1 files changed, 42 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Wed Jul 17 09:38:11 2013 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Wed Jul 17 12:16:33 2013 -0400
@@ -24,10 +24,7 @@
  */
 package javafx.scene;
 
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -36,12 +33,18 @@
 import java.util.Map.Entry;
 import java.util.Set;
 
-import javafx.application.Platform;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableMap;
-import javafx.css.*;
+import javafx.css.CssMetaData;
+import javafx.css.FontCssMetaData;
+import javafx.css.ParsedValue;
+import javafx.css.PseudoClass;
+import javafx.css.StyleConverter;
+import javafx.css.StyleOrigin;
+import javafx.css.Styleable;
+import javafx.css.StyleableProperty;
 import javafx.scene.text.Font;
 import javafx.scene.text.FontPosture;
 import javafx.scene.text.FontWeight;
@@ -50,7 +53,6 @@
 import com.sun.javafx.css.CalculatedValue;
 import com.sun.javafx.css.CascadingStyle;
 import com.sun.javafx.css.CssError;
-import com.sun.javafx.css.Declaration;
 import com.sun.javafx.css.ParsedValueImpl;
 import com.sun.javafx.css.PseudoClassState;
 import com.sun.javafx.css.Rule;
@@ -63,7 +65,6 @@
 import com.sun.javafx.css.StyleMap;
 import com.sun.javafx.css.Stylesheet;
 import com.sun.javafx.css.converters.FontConverter;
-import com.sun.javafx.css.parser.CSSParser;
 import sun.util.logging.PlatformLogger;
 import sun.util.logging.PlatformLogger.Level;
 
@@ -85,13 +86,6 @@
      */
     static CssStyleHelper createStyleHelper(Node node) {
 
-        // If this node had a style helper, then reset properties to their initial value
-        // since the node might not have a style helper after this call
-        if (node.styleHelper != null && node.styleHelper.cacheContainer != null) {
-            node.styleHelper.resetToInitialValues(node);
-            node.styleHelper.cacheContainer.cssSetProperties.clear();
-        }
-
         // need to know how far we are to root in order to init arrays.
         // TODO: should we hang onto depth to avoid this nonsense later?
         // TODO: is there some other way of knowing how far from the root a node is?
@@ -116,10 +110,24 @@
         final StyleMap styleMap =
                 StyleManager.getInstance().findMatchingStyles(node, triggerStates);
 
+        if (node.styleHelper != null) {
+
+            boolean sameMap = false;
+
+            if (styleMap != null) {
+                StyleMap currentMap = node.styleHelper.getStyleMap(node);
+                // check instance equality!
+                if (currentMap == styleMap) {
+                    return node.styleHelper;
+                }
+            }
+
+        }
 
         if (styleMap == null || styleMap.isEmpty()) {
 
             boolean mightInherit = false;
+
             final List<CssMetaData<? extends Styleable, ?>> props = node.getCssMetaData();
 
             final int pMax = props != null ? props.size() : 0;
@@ -133,8 +141,16 @@
             }
 
             if (mightInherit == false) {
+
+                // If this node had a style helper, then reset properties to their initial value
+                // since the node won't have a style helper after this call
+                if (node.styleHelper != null) {
+                    node.styleHelper.resetToInitialValues(node);
+                }
+
                 return null;
             }
+
         }
 
         final CssStyleHelper helper = new CssStyleHelper();
@@ -170,6 +186,13 @@
         }
 
         helper.cacheContainer = new CacheContainer(node, styleMap, depth);
+
+        // If this node had a style helper, then reset properties to their initial value
+        // since the style map might now be different
+        if (node.styleHelper != null) {
+            node.styleHelper.resetToInitialValues(node);
+        }
+
         return helper;
     }
 
@@ -273,7 +296,11 @@
                 cacheContainer.cssSetProperties == null ||
                 cacheContainer.cssSetProperties.isEmpty()) return;
 
-        for (Entry<CssMetaData, CalculatedValue> resetValues : cacheContainer.cssSetProperties.entrySet()) {
+        // RT-31714 - make a copy of the entry set and clear the cssSetProperties immediately.
+        Set<Entry<CssMetaData, CalculatedValue>> entrySet = new HashSet<>(cacheContainer.cssSetProperties.entrySet());
+        cacheContainer.cssSetProperties.clear();
+
+        for (Entry<CssMetaData, CalculatedValue> resetValues : entrySet) {
 
             final CssMetaData metaData = resetValues.getKey();
             final StyleableProperty styleableProperty = metaData.getStyleableProperty(styleable);