changeset 10919:a9c1ee0bc270

8196827: test.javafx.scene.control.ComboBoxTest - generates NullPointerException Reviewed-by: kcr, arapte
author aghaisas
date Thu, 10 May 2018 10:32:22 +0530
parents 260d27966d94
children 9c4d93d56f75
files modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java
diffstat 2 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java	Tue May 08 18:55:00 2018 -0700
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ComboBoxPopupControl.java	Thu May 10 10:32:22 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
@@ -403,6 +403,11 @@
     }
 
     private void positionAndShowPopup() {
+        final ComboBoxBase<T> comboBoxBase = getSkinnable();
+        if (comboBoxBase.getScene() == null) {
+            return;
+        }
+
         final PopupControl _popup = getPopup();
         _popup.getScene().setNodeOrientation(getSkinnable().getEffectiveNodeOrientation());
 
@@ -415,10 +420,9 @@
         popupNeedsReconfiguring = true;
         reconfigurePopup();
 
-        final ComboBoxBase<T> comboBoxBase = getSkinnable();
         _popup.show(comboBoxBase.getScene().getWindow(),
-                snapPositionX(p.getX()),
-                snapPositionY(p.getY()));
+                    snapPositionX(p.getX()),
+                    snapPositionY(p.getY()));
 
         popupContent.requestFocus();
 
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java	Tue May 08 18:55:00 2018 -0700
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/ComboBoxTest.java	Thu May 10 10:32:22 2018 +0530
@@ -77,6 +77,7 @@
 import javafx.util.Callback;
 import javafx.util.StringConverter;
 
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -108,12 +109,22 @@
      ********************************************************************/
 
     @Before public void setup() {
+        Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
+            if (throwable instanceof RuntimeException) {
+                throw (RuntimeException)throwable;
+            } else {
+                Thread.currentThread().getThreadGroup().uncaughtException(thread, throwable);
+            }
+        });
+
         comboBox = new ComboBox<String>();
         comboBox.setSkin(new ComboBoxListViewSkin<>(comboBox));
         sm = comboBox.getSelectionModel();
     }
 
-
+    @After public void cleanup() {
+        Thread.currentThread().setUncaughtExceptionHandler(null);
+    }
 
     /*********************************************************************
      *                                                                   *
@@ -634,6 +645,10 @@
     }
 
     @Test public void ensureImpl_getPseudoClassStateReturnsValidValue() {
+        Stage stage = new Stage();
+        Scene scene = new Scene(comboBox);
+        stage.setScene(scene);
+
         Set<PseudoClass> pseudoClassStates = comboBox.getPseudoClassStates();
         assertFalse(comboBox.isEditable());
         assertTrue(pseudoClassStates.size() >= 0);
@@ -708,6 +723,10 @@
     }
 
     @Test public void ensureCanToggleShowing() {
+        Stage stage = new Stage();
+        Scene scene = new Scene(comboBox);
+        stage.setScene(scene);
+
         comboBox.show();
         assertTrue(comboBox.isShowing());
         comboBox.hide();
@@ -715,6 +734,10 @@
     }
 
     @Test public void ensureCanNotToggleShowingWhenDisabled() {
+        Stage stage = new Stage();
+        Scene scene = new Scene(comboBox);
+        stage.setScene(scene);
+
         comboBox.setDisable(true);
         comboBox.show();
         assertFalse(comboBox.isShowing());