changeset 1393:80668368c867

RT-23140: NPE in getStyleHelper if stylesheet fails to load. Check if stylesheet is null and also check if stylesheet List<Rule> is null or empty. If so, move on to next stylesheet.
author David Grieve<david.grieve@oracle.com>
date Mon, 02 Jul 2012 14:16:41 -0400
parents 121a87ea1d97
children 3e1c680c584d
files javafx-ui-common/src/com/sun/javafx/css/StyleManager.java javafx-ui-common/test/unit/com/sun/javafx/css/StylesheetTest.java
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Mon Jul 02 14:15:51 2012 -0400
+++ b/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java	Mon Jul 02 14:16:41 2012 -0400
@@ -1232,8 +1232,11 @@
                 }                    
 
                 for (int i = 0, imax = stylesheetsToProcess.size(); i < imax; i++) {
-                    final Stylesheet ss = stylesheetsToProcess.get(i);
-                    final List<Rule> stylesheetRules = ss.getRules();
+                    final Stylesheet ss = stylesheetsToProcess.get(i); 
+                    
+                    final List<Rule> stylesheetRules = ss != null ? ss.getRules() : null;
+                    if (stylesheetRules == null || stylesheetRules.isEmpty()) continue;
+
                     for (int j = 0, jmax = stylesheetRules.size(); j < jmax; j++) {
                         Rule rule = stylesheetRules.get(j);
                         boolean mightApply = rule.mightApply(className, id, styleClass);
--- a/javafx-ui-common/test/unit/com/sun/javafx/css/StylesheetTest.java	Mon Jul 02 14:15:51 2012 -0400
+++ b/javafx-ui-common/test/unit/com/sun/javafx/css/StylesheetTest.java	Mon Jul 02 14:16:41 2012 -0400
@@ -28,6 +28,10 @@
 import java.net.URL;
 import java.util.Collections;
 import java.util.List;
+import javafx.scene.Group;
+import javafx.scene.Scene;
+import javafx.scene.shape.Rectangle;
+import javafx.stage.Stage;
 import org.junit.*;
 import static org.junit.Assert.*;
 
@@ -192,4 +196,27 @@
         fail("The test case is a prototype.");
     }
      */
+    
+    @Test
+    public void testRT_23140() {
+
+        try {
+            Group root = new Group();
+            root.getChildren().add(new Rectangle(50,50));        
+            Scene scene = new Scene(root, 500, 500);
+            root.getStylesheets().add("bogus.css");
+            Stage stage = new Stage();
+            stage.setScene(scene);
+            stage.show();
+        } catch (NullPointerException e) {
+            // RT-23140 is supposed to fix the NPE. Did it?
+            fail("Test purpose failed: " + e.toString());
+        } catch (Exception e) {
+            // Something other than an NPE should still raise a red flag,
+            // but the exception is not what RT-23140 fixed.
+            fail("Exception not expected: " + e.toString());
+        }
+        
+    }
+    
 }