-
Bug
-
Resolution: Fixed
-
P4
-
jfx16
-
b08
@Test
public void testOnInputMethodTextChangedNPE() {
String initialText = "some text";
String prefix = "from input event";
TextField field = new TextField(initialText);
installDefaultSkin(field);
InputMethodEvent event = new InputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
List.of(), prefix, 0);
Event.fireEvent(field, event);
assertEquals("sanity: prefix must be committed", prefix + initialText, field.getText());
replaceSkin(field);
Event.fireEvent(field, event);
assertEquals(" prefix must be committed again", prefix + prefix + initialText, field.getText());
}
This throws an NPE before the fix because the handler installed by the skin _is not_ removed, and fails the assertion because the handler installed by the skin _is_ removed ;)
The problem is the installation pattern which sets its own singleton handler if there is none on the control:
if (control.getOnInputMethodTextChanged() == null) {
control.setOnInputMethodTextChanged(event -> {
handleInputMethodEvent(event);
});
}
When replacing the skin, the new skin's constructor is run while the control is still attached to the old skin - at that time, the field's handler is not null (because set by the old skin), so the new skin doesn't replace it. In dispose, the handler is either removed (after the fix) leaving the control without handler or not removed (before the fix) leading to the NPE.
This pattern is copied to ComboBoxPopupControl to fix
- blocks
-
JDK-8241364 ☂ Cleanup skin implementations to allow switching
- Open
- is blocked by
-
JDK-8290844 Add Skin.install() method
- Resolved
- relates to
-
JDK-8093590 Controls skins should not call setOnMouseXXX to add mouse handlers in skins.
- Resolved
-
JDK-8301832 InputMethodEvents are not enabled for text input controls
- Resolved
-
JDK-8240506 TextFieldSkin/Behavior: misbehavior on switching skin
- Resolved
-
JDK-8301219 JavaFX crash when closing with the escape key
- Resolved
-
JDK-8096136 [ComboBox] Editable ComboBox doesn't handle IM events if it gets focus through focus traversal keys.
- Closed
-
JDK-8290844 Add Skin.install() method
- Resolved