Skip to content

Commit e856a58

Browse files
author
Jeanette Winzenburg
committed
8246202: ChoiceBoxSkin: misbehavior on switching skin, part 2
Reviewed-by: kcr, aghaisas
1 parent eb626aa commit e856a58

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/skin/ChoiceBoxSkin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public ChoiceBoxSkin(ChoiceBox<T> control) {
147147
initialize();
148148

149149
itemsObserver = observable -> updateChoiceBoxItems();
150-
control.itemsProperty().addListener(new WeakInvalidationListener(itemsObserver));
150+
control.itemsProperty().addListener(itemsObserver);
151151

152152
control.requestLayout();
153153
registerChangeListener(control.selectionModelProperty(), e -> updateSelectionModel());
@@ -206,6 +206,9 @@ public ChoiceBoxSkin(ChoiceBox<T> control) {
206206

207207
/** {@inheritDoc} */
208208
@Override public void dispose() {
209+
if (getSkinnable() == null) return;
210+
// removing itemsObserver fixes NP on setting items
211+
getSkinnable().itemsProperty().removeListener(itemsObserver);
209212
// removing the content listener fixes NPE from listener
210213
if (choiceBoxItems != null) {
211214
choiceBoxItems.removeListener(weakChoiceBoxItemsListener);

modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/SkinCleanupTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@ public void testListViewSetItems() {
111111
//-------- choiceBox, toolBar
112112

113113
/**
114-
* FIXME: Left-over from ChoiceBox fix.
115114
* NPE on sequence setItems -> modify items after skin is replaced.
116115
*/
117-
@Test @Ignore("8246202")
116+
@Test
118117
public void testChoiceBoxSetItems() {
119118
ChoiceBox<String> box = new ChoiceBox<>();
120119
installDefaultSkin(box);

0 commit comments

Comments
 (0)