-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
jfx20, 8, jfx21, jfx22, jfx23
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Pressing Ctrl+Z in a TextInputControl bound to a property (and the property bound back to TextInputControl.textProperty()) leads to:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot read field "next" because "this.undoChange" is null
at javafx.controls@22.0.1/javafx.scene.control.TextInputControl.updateUndoRedoState(TextInputControl.java:1250)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a TextField. Create a separate SimpleStringProperty. Bind a change of TextField.textProperty() to SimpleStringProperty.set() and vice versa. Start the application. Type something in the field. Press Ctrl+Z. See an NPE:
Java:
TextField textField = new TextField();
textField.setPromptText("Type something and then press Ctrl+Z.");
vbox.getChildren().add(textField);
SimpleStringProperty textProperty = new SimpleStringProperty();
textProperty.addListener((_, _, newValue) -> textField.textProperty().set(newValue));
textField.textProperty().addListener((_, _, newValue) -> textProperty.set(newValue));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Undo is executed.
---------- BEGIN SOURCE ----------
package org.jabreftest.test.javafxreproducer;
import java.io.IOException;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Dialog<String> alert = new Dialog<>();
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you! With some longer text to show the issue");
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.initOwner(stage.getOwner());
alert.setResizable(true);
DialogPane dlgPane = new DialogPane();
dlgPane.getButtonTypes().addAll(ButtonType.CANCEL);
VBox vbox = new VBox();
vbox.setPrefWidth(400);
vbox.setPrefHeight(200);
TextField textField = new TextField();
textField.setPromptText("Type something and then press Ctrl+Z.");
vbox.getChildren().add(textField);
SimpleStringProperty textProperty = new SimpleStringProperty();
textProperty.addListener((_, _, newValue) -> textField.textProperty().set(newValue));
textField.textProperty().addListener((_, _, newValue) -> textProperty.set(newValue));
dlgPane.setContent(vbox);
alert.setDialogPane(dlgPane);
alert.showAndWait();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
textInputControl.addEventFilter(KeyEvent.ANY, e -> {
if (e.getEventType() == KeyEvent.KEY_PRESSED && e.isShortcutDown()) {
switch (e.getCode()) {
case Y -> {
redoAction.execute();
e.consume();
}
case Z -> {
undoAction.execute();
e.consume();
}
}
}
});
FREQUENCY : always
Pressing Ctrl+Z in a TextInputControl bound to a property (and the property bound back to TextInputControl.textProperty()) leads to:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot read field "next" because "this.undoChange" is null
at javafx.controls@22.0.1/javafx.scene.control.TextInputControl.updateUndoRedoState(TextInputControl.java:1250)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a TextField. Create a separate SimpleStringProperty. Bind a change of TextField.textProperty() to SimpleStringProperty.set() and vice versa. Start the application. Type something in the field. Press Ctrl+Z. See an NPE:
Java:
TextField textField = new TextField();
textField.setPromptText("Type something and then press Ctrl+Z.");
vbox.getChildren().add(textField);
SimpleStringProperty textProperty = new SimpleStringProperty();
textProperty.addListener((_, _, newValue) -> textField.textProperty().set(newValue));
textField.textProperty().addListener((_, _, newValue) -> textProperty.set(newValue));
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Undo is executed.
---------- BEGIN SOURCE ----------
package org.jabreftest.test.javafxreproducer;
import java.io.IOException;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Dialog<String> alert = new Dialog<>();
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("I have a great message for you! With some longer text to show the issue");
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.initOwner(stage.getOwner());
alert.setResizable(true);
DialogPane dlgPane = new DialogPane();
dlgPane.getButtonTypes().addAll(ButtonType.CANCEL);
VBox vbox = new VBox();
vbox.setPrefWidth(400);
vbox.setPrefHeight(200);
TextField textField = new TextField();
textField.setPromptText("Type something and then press Ctrl+Z.");
vbox.getChildren().add(textField);
SimpleStringProperty textProperty = new SimpleStringProperty();
textProperty.addListener((_, _, newValue) -> textField.textProperty().set(newValue));
textField.textProperty().addListener((_, _, newValue) -> textProperty.set(newValue));
dlgPane.setContent(vbox);
alert.setDialogPane(dlgPane);
alert.showAndWait();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
textInputControl.addEventFilter(KeyEvent.ANY, e -> {
if (e.getEventType() == KeyEvent.KEY_PRESSED && e.isShortcutDown()) {
switch (e.getCode()) {
case Y -> {
redoAction.execute();
e.consume();
}
case Z -> {
undoAction.execute();
e.consume();
}
}
}
});
FREQUENCY : always