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

keyboard event NullPointerException with JMenuBar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5
    • client-libs



      Name: rk38400 Date: 04/07/98


      In Swing 1.0, if a frame has a JMenuBar, and any
      submenu of that menubar is empty, a NullPointerException
      will be throw during event processing for any
      keyboard action.

      Compile and run the following code:

      import com.sun.java.swing.*;
      import java.awt.*;

      public class foo
         {
         public static void main(String[] args)
         {
            JFrame frame = new JFrame();
            JTextArea text = new JTextArea();
            JPanel panel = new JPanel(new GridLayout(1,1));
            panel.setPreferredSize(new Dimension(100,100));
            panel.add(text);
            frame.setContentPane(panel);

            JMenuBar menu = new JMenuBar();
            menu.add(new JMenu("something"));

            frame.setJMenuBar(menu);

            frame.pack();
            frame.setVisible(true);
            frame.validate();
            frame.repaint();
         }
         }

      Now, type a letter in the text field: The program
      will dump 2 identical stack traces:

      Exception occurred during event dispatching:
      java.lang.NullPointerException:
      at com.sun.java.swing.JMenuBar.bindingForKeyStrokeRecursive(JMenuBar.java:559)
      at com.sun.java.swing.JMenuBar.bindingForKeyStroke(JMenuBar.java:532)
      at com.sun.java.swing.JComponent.processKeyBinding(JComponent.java:1345)
      at com.sun.java.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:1402)
      at com.sun.java.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:1409)
      at com.sun.java.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:1409)
      at com.sun.java.swing.JComponent.processKeyBindingsForAllComponents(JComponent.java:1409)
      at com.sun.java.swing.JComponent.processKeyBindings(JComponent.java:1391)
      at com.sun.java.swing.JComponent.processKeyEvent(JComponent.java:1277)
      at java.awt.Component.processEvent(Component.java:2138)
      at java.awt.Container.processEvent(Container.java:894)
      at java.awt.Component.dispatchEventImpl(Component.java:1764)
      at java.awt.Container.dispatchEventImpl(Container.java:939)
      at java.awt.Component.dispatchEvent(Component.java:1704)
      at java.awt.LightweightDispatcher.processKeyEvent(Container.java:1416)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1402)
      at java.awt.Container.dispatchEventImpl(Container.java:926)
      at java.awt.Window.dispatchEventImpl(Window.java:443)
      at java.awt.Component.dispatchEvent(Component.java:1704)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

      I reported this a few days ago, but did not receive
      an automatic reply.
      (Review ID: 25834)
      ======================================================================

            gsaab Georges Saab
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: