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

Mac: OS X System MenuBar causes null pointer exception with a graphic that has a null Image.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • javafx
    • OS X 10.9 with Java 1.8.0ea b117

      If you use the system menubar in OS X with a MenuItem that has an ImageView set as the graphic but a null image then GlassSystemMenu throws a NullPointerException:

      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at com.sun.javafx.tk.quantum.GlassSystemMenu.getPixels(GlassSystemMenu.java:322)
      at com.sun.javafx.tk.quantum.GlassSystemMenu.insertMenuItem(GlassSystemMenu.java:255)
      at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenuItem(GlassSystemMenu.java:198)
      at com.sun.javafx.tk.quantum.GlassSystemMenu.insertMenu(GlassSystemMenu.java:165)
      at com.sun.javafx.tk.quantum.GlassSystemMenu.addMenu(GlassSystemMenu.java:119)

      You can see this issue if you run the following test code:

      *************************************************************************

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;


      public class MenuBarTest extends Application {

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

      Menu menu = new Menu("File");
      menu.getItems().add(new MenuItem("test", new ImageView((Image)null)));

      MenuBar menuBar = new MenuBar();
      menuBar.setUseSystemMenuBar(true);
      menuBar.getMenus().add(menu);
      BorderPane pane = new BorderPane();
      pane.setTop(menuBar);
      primaryStage.setScene( new Scene(pane, 400, 300) );
      primaryStage.centerOnScreen();

      primaryStage.show();

      }

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

      }

            anthony Anthony Petrov (Inactive)
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: