changeset 10900:f7643f961ac6

8185854: NPE on non-editable ComboBox in TabPane with custom Skin Reviewed-by: kcr, arapte
author aghaisas
date Fri, 13 Apr 2018 16:09:47 +0530
parents d06276cd8a40
children b942977b44eb
files modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/customSkins/JDK8185854/ComboBoxCustomSkin.java modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/customSkins/JDK8185854/TabPaneCustomSkin.java modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java modules/javafx.controls/src/test/resources/test/javafx/scene/control/JDK_8185854.css
diffstat 5 files changed, 135 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java	Fri Apr 13 14:02:01 2018 +0530
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxListViewSkin.java	Fri Apr 13 16:09:47 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -176,7 +176,10 @@
             listView.requestLayout();
         });
         registerChangeListener(control.converterProperty(), e -> updateListViewItems());
-        registerChangeListener(control.buttonCellProperty(), e -> updateButtonCell());
+        registerChangeListener(control.buttonCellProperty(), e -> {
+            updateButtonCell();
+            updateDisplayArea();
+        });
         registerChangeListener(control.valueProperty(), e -> {
             updateValue();
             control.fireEvent(new ActionEvent());
@@ -464,7 +467,7 @@
                 comboBox.getButtonCell() : getDefaultCellFactory().call(listView);
         buttonCell.setMouseTransparent(true);
         buttonCell.updateListView(listView);
-        updateDisplayArea();
+
         // As long as the screen-reader is concerned this node is not a list item.
         // This matters because the screen-reader counts the number of list item
         // within combo and speaks it to the user.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/customSkins/JDK8185854/ComboBoxCustomSkin.java	Fri Apr 13 16:09:47 2018 +0530
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.com.sun.javafx.scene.control.customSkins.JDK8185854;
+
+import javafx.scene.control.ComboBox;
+import javafx.scene.control.TextField;
+import javafx.scene.control.skin.ComboBoxListViewSkin;
+
+public class ComboBoxCustomSkin<T> extends ComboBoxListViewSkin<T> {
+    public ComboBoxCustomSkin(ComboBox<T> comboBox) {
+        super(comboBox);
+    }
+
+    @Override
+    protected TextField getEditor() {
+        return super.getEditor();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/customSkins/JDK8185854/TabPaneCustomSkin.java	Fri Apr 13 16:09:47 2018 +0530
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package test.com.sun.javafx.scene.control.customSkins.JDK8185854;
+
+import javafx.scene.control.TabPane;
+import javafx.scene.control.skin.TabPaneSkin;
+
+public class TabPaneCustomSkin extends TabPaneSkin
+{
+    public TabPaneCustomSkin(TabPane tabPane) {
+        super(tabPane);
+    }
+}
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java	Fri Apr 13 14:02:01 2018 +0530
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java	Fri Apr 13 16:09:47 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -62,10 +62,14 @@
 import javafx.scene.control.SelectionModel;
 import javafx.scene.control.SelectionModelShim;
 import javafx.scene.control.SingleSelectionModel;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
 import javafx.scene.control.TextField;
 import javafx.scene.control.Tooltip;
 import javafx.scene.control.skin.VirtualFlow;
 import javafx.scene.input.KeyCode;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.FlowPane;
 import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
 import javafx.scene.shape.Circle;
@@ -1995,4 +1999,44 @@
         assertEquals(2, count.get());
         assertEquals("New Value", comboBox.getValue());
     }
+
+    private int skinChangedCount = 0;
+    @Test public void test_JDK_8185854() {
+        final FlowPane comboPane = new FlowPane(10, 10);
+        ComboBox combo = new ComboBox<String>();
+
+        combo.skinProperty().addListener((o, oldSkin, newSkin) -> {
+            skinChangedCount++;
+        });
+
+        combo.setDisable(false);
+        combo.setEditable(false);
+
+        comboPane.getChildren().add(combo);
+
+        TabPane tabPane = new TabPane();
+        Tab tab = new Tab();
+        tab.setText("ComboBox");
+        tab.setContent(comboPane);
+        tabPane.getTabs().add(tab);
+
+        BorderPane p = new BorderPane();
+        p.setCenter(tabPane);
+
+        Scene scene = new Scene(p);
+        scene.getStylesheets().add(ComboBoxTest.class.getResource("JDK_8185854.css").toExternalForm());
+
+        Toolkit tk = Toolkit.getToolkit();
+
+        Stage stage = new Stage();
+        stage.setScene(scene);
+        stage.setWidth(500);
+        stage.setHeight(400);
+
+        stage.show();
+
+        tk.firePulse();
+
+        assertEquals("ComboBox skinProperty changed more than once, which is not expected.", 1, skinChangedCount);
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/javafx.controls/src/test/resources/test/javafx/scene/control/JDK_8185854.css	Fri Apr 13 16:09:47 2018 +0530
@@ -0,0 +1,7 @@
+.combo-box {
+   -fx-skin: "test.com.sun.javafx.scene.control.customSkins.JDK8185854.ComboBoxCustomSkin";
+}
+
+.tab-pane {
+    -fx-skin: "test.com.sun.javafx.scene.control.customSkins.JDK8185854.TabPaneCustomSkin";
+}