-
Bug
-
Resolution: Fixed
-
P4
-
9
-
jdk9-ea-104
Running the example below fails with the stacktrace (excerpt)
Caused by: java.lang.NullPointerException
at javafx.scene.control.TextInputControl.updateText(TextInputControl.java:1218)
at javafx.scene.control.TextInputControl.access$300(TextInputControl.java:79)
at javafx.scene.control.TextInputControl$5.invalidated(TextInputControl.java:320)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
at javafx.scene.control.TextInputControl.setTextFormatter(TextInputControl.java:334)
The technical reason seems to be the defaultConverter installed by CellUtils - its toString returns a null if the input param is null. That differs from all (?) other StringConverters in core which return an empty string.
Not sure who's the culprit: on the one hand, null behaviour/return value in StringConverter is not specified, on the other hand TextProperty usually takes care of passing a null as empty string to Content - but replace doesn't.
The example:
public class ComboBoxTableCellConverterAndTextFormatter extends Application {
private Parent getContent() {
TextField field = new TextField("some dummy");
TextFormatter formatter = new TextFormatter(new ComboBoxTableCell().getConverter());
// the default in TextFormatter is okay
//TextFormatter formatter = new TextFormatter(TextFormatter.IDENTITY_STRING_CONVERTER);
field.setTextFormatter(formatter);
return field;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent()));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Caused by: java.lang.NullPointerException
at javafx.scene.control.TextInputControl.updateText(TextInputControl.java:1218)
at javafx.scene.control.TextInputControl.access$300(TextInputControl.java:79)
at javafx.scene.control.TextInputControl$5.invalidated(TextInputControl.java:320)
at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
at javafx.scene.control.TextInputControl.setTextFormatter(TextInputControl.java:334)
The technical reason seems to be the defaultConverter installed by CellUtils - its toString returns a null if the input param is null. That differs from all (?) other StringConverters in core which return an empty string.
Not sure who's the culprit: on the one hand, null behaviour/return value in StringConverter is not specified, on the other hand TextProperty usually takes care of passing a null as empty string to Content - but replace doesn't.
The example:
public class ComboBoxTableCellConverterAndTextFormatter extends Application {
private Parent getContent() {
TextField field = new TextField("some dummy");
TextFormatter formatter = new TextFormatter(new ComboBoxTableCell().getConverter());
// the default in TextFormatter is okay
//TextFormatter formatter = new TextFormatter(TextFormatter.IDENTITY_STRING_CONVERTER);
field.setTextFormatter(formatter);
return field;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent()));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}