Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8094185

Null pointer when a button without a mnemonic is re-added to a scene and alt is pressed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8u20
    • javafx
    • Java 8u20 b11 Linux

    Description

      I believe the fix for bug RT-36336 introduced this null pointer exception. It looks like LabeledSkinBase now always responds to a new scene by adding a mnemonic even if it doesn't have one.

      Run the following test class:

      1. Press alt to see mnemonics set on the checkbox but not on the button.

      2. Uncheck the checkbox which will remove the button. Press alt again and everything is fine.

      3. Re-check the checkbox to add the button back. Press alt a third time and the null pointer exception will be thrown.

      ***************************************** Test Class ***********************************************************
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.CheckBox;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Region;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class MnemonicsTest extends Application {

         @Override public void start(final Stage primaryStage) throws Exception {

            final CheckBox button1 = new CheckBox("_Test with Mnemonic");
            button1.setSelected(true);
            final Button button2 = new Button("Test without Mnemonic");
            
            primaryStage.centerOnScreen();
            primaryStage.setHeight(350);
            primaryStage.setWidth(500);
            
            final HBox box = new HBox(20, button1, button2);
            box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
            box.setAlignment(Pos.BASELINE_LEFT);
            primaryStage.setScene(new Scene(new StackPane(box)));
            
            button1.setOnAction(new EventHandler<ActionEvent>() {
               @Override public void handle(ActionEvent event) {
                  if ( button1.isSelected() && !box.getChildren().contains(button2)) {
                     box.getChildren().add(button2);
                  } else {
                     box.getChildren().remove(button2);
                  }
               }
            });

            primaryStage.show();

         }

         public static void main(String[] args) throws Exception {
            launch(args);
         }

      }

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: