Skip to content

Commit d1a7ebd

Browse files
committed
8279514: NPE on clearing value of IntegerSpinnerValueFactory
Reviewed-by: mhanl, kcr
1 parent eb8f2fe commit d1a7ebd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/SpinnerValueFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public ListSpinnerValueFactory(@NamedArg("items") ObservableList<T> items) {
272272
});
273273

274274
valueProperty().addListener((o, oldValue, newValue) -> {
275+
if (newValue == null) return;
276+
275277
// when the value is set, we need to react to ensure it is a
276278
// valid value (and if not, blow up appropriately)
277279
int newIndex = -1;
@@ -468,6 +470,8 @@ public IntegerSpinnerValueFactory(@NamedArg("min") int min,
468470
setConverter(new IntegerStringConverter());
469471

470472
valueProperty().addListener((o, oldValue, newValue) -> {
473+
if (newValue == null) return;
474+
471475
// when the value is set, we need to react to ensure it is a
472476
// valid value (and if not, blow up appropriately)
473477
if (newValue < getMin()) {
@@ -957,6 +961,8 @@ public LocalDateSpinnerValueFactory(@NamedArg("min") LocalDate min,
957961
});
958962

959963
valueProperty().addListener((o, oldValue, newValue) -> {
964+
if (newValue == null) return;
965+
960966
// when the value is set, we need to react to ensure it is a
961967
// valid value (and if not, blow up appropriately)
962968
if (getMin() != null && newValue.isBefore(getMin())) {
@@ -1213,6 +1219,8 @@ public LocalTimeSpinnerValueFactory(@NamedArg("min") LocalTime min,
12131219
});
12141220

12151221
valueProperty().addListener((o, oldValue, newValue) -> {
1222+
if (newValue == null) return;
1223+
12161224
// when the value is set, we need to react to ensure it is a
12171225
// valid value (and if not, blow up appropriately)
12181226
if (getMin() != null && newValue.isBefore(getMin())) {

modules/javafx.controls/src/test/java/test/javafx/scene/control/SpinnerTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import javafx.collections.FXCollections;
3030
import javafx.collections.ObservableList;
31+
import org.junit.After;
3132
import org.junit.AfterClass;
3233
import org.junit.Before;
3334
import org.junit.BeforeClass;
@@ -122,8 +123,20 @@ public class SpinnerTest {
122123
LocalTime.MIN, LocalTime.MAX,
123124
LocalTime.now(), 1, ChronoUnit.HOURS);
124125
localTimeValueFactory = localTimeSpinner.getValueFactory();
126+
127+
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> {
128+
if (throwable instanceof RuntimeException) {
129+
throw (RuntimeException)throwable;
130+
} else {
131+
Thread.currentThread().getThreadGroup().uncaughtException(thread, throwable);
132+
}
133+
});
125134
}
126135

136+
@After
137+
public void tearDown() {
138+
Thread.currentThread().setUncaughtExceptionHandler(null);
139+
}
127140

128141
/***************************************************************************
129142
* *
@@ -1479,4 +1492,29 @@ public void test_jdk_8150946_testCommit_invalid_wrongType() {
14791492
stage.hide();
14801493
}
14811494
}
1495+
1496+
@Test public void testSetValueNull_IntegerSpinner() {
1497+
intValueFactory.setValue(null);
1498+
assertNull(intSpinner.getValue());
1499+
}
1500+
1501+
@Test public void testSetValueNull_DoubleSpinner() {
1502+
dblValueFactory.setValue(null);
1503+
assertNull(dblSpinner.getValue());
1504+
}
1505+
1506+
@Test public void testSetValueNull_ListSpinner() {
1507+
listValueFactory.setValue(null);
1508+
assertNull(listSpinner.getValue());
1509+
}
1510+
1511+
@Test public void testSetValueNull_LocalDateSpinner() {
1512+
localDateValueFactory.setValue(null);
1513+
assertNull(localDateSpinner.getValue());
1514+
}
1515+
1516+
@Test public void testSetValueNull_LocalTimeSpinner() {
1517+
localTimeValueFactory.setValue(null);
1518+
assertNull(localTimeSpinner.getValue());
1519+
}
14821520
}

0 commit comments

Comments
 (0)