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

Kestrel I, jMenu app causes null pointer exceptions

    XMLWordPrintable

Details

    • 02
    • x86
    • generic, windows_98, windows_nt
    • Verified

    Backports

      Description



        Name: vr73486 Date: 10/12/99

        The following app causes null pointer exceptions. Run the app on any platform.

        1. Invoke the application, do not resize the window
        2. open the rightmost menu such that it extends outside the right side of the frame
        3. pull right in the first item in the rightmost menu
        4. click on the next pullright (an empty menu)
        5. open the second menu fron the right and click in the firse menu item
        6. open the first menu from the right and then open the first pullright
        7. move the mouse cursor back and forth from the first menu to the pullright

        You should see a null pointer stack trace. You might have to play with the
        above instructions a bit.


        import java.awt.*
        import java.awt.event.*
        import javax.swing.*

        public class jMenu extends JApplet
        {
                public void init()
                {
                        JFrame frame = new JFrame("\u0645\u062b\u0627\u0644")
                        frame.setJMenuBar(new jMenuX())
                        frame.pack()
                        frame.setVisible(true)
                        frame.setSize(300,300)
                }


                public static void main(String[] argv)
                {
                        JFrame frame = new JFrame("\u0645\u062b\u0627\u0644")
                        frame.setJMenuBar(new jMenuX())
                        frame.pack()
                        frame.setVisible(true)
                        frame.setSize(300,300)
                }

        }


        class jMenuX extends JMenuBar implements ActionListener
        {

                String[] fileItems = new String[] { "\u062c\u062f\u064a\u062f\u0020\u05d7\u05d3\u05e9", "\u0641\u062a\u062d\u0020\u0645\u0644\u0641", "\u062d\u0641\u0638\u0020", "\u05d9\u05e6\u05d9\u05d0\u05d4\u0020\u062e\u0631\u0648\u062c" } String[] editItems = new String[] { "\u05d4\u05e2\u05ea\u05e7\u0020\u0625\u0646\u0633\u062e", "\u05d7\u05ea\u05d5\u05da\u0020\u0625\u0642\u0637\u0639", "\u05ea\u05d5\u05e1\u05d9\u05e3\u0020\u0623\u0636\u0641", "\u0623\u0644\u0635\u0642\u0020\u05ea\u05e2\u05e1\u05d4" }
                char[] fileShortcuts = { 'a','z','q','w' }
                char[] editShortcuts = { 'x','c','v','k' }
                public jMenuX() {
                JMenu fileMenu = new JMenu("\u0645\u0644\u0641\u0020\u05e7\u05d5\u05d1\u05e5") JMenu editMenu = new JMenu("\u05d0\u05e4\u05e9\u05e8\u05d9\u05d5\u05ea\u0020\u062e\u064a\u0627\u0631\u0627\u062a") JMenu otherMenu = new JMenu("\u05d0\u05d7\u05e8\u0020\u0627\u062e\u0631")
                JMenu subMenu = new JMenu("\u05ea\u05e4\u05e8\u05d9\u05d8\u0020\u0642\u0627\u0626\u0645\u0629")
                JMenu subMenu2 = new JMenu("\u05ea\u05e4\u05e8\u05d9\u05d8\u0020\u05d7\u05d3\u05e9\u0020\u0642\u0627\u0626\u0645\u0629\u0020\u062c\u062f\u064a\u062f\u0629")

                fileMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
                editMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
                subMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
                subMenu2.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))

                for (int i=0 i < fileItems.length i++)
                {
                    JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i])
                    item.addActionListener(this)
                    fileMenu.add(item)
                }

                for (int i=0 i < editItems.length i++)
                {

                    JMenuItem item = new JMenuItem(editItems[i])
                    item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i],
                                         java.awt.Event.CTRL_MASK, false))
                    item.addActionListener(this)
                    editMenu.add(item)
                }

                editMenu.insertSeparator(1)

                JMenuItem item
                subMenu2.add(item = new JMenuItem(""))
                item.addActionListener(this)
                subMenu.add(item = new JMenuItem(""))
                item.addActionListener(this)
                subMenu.add(subMenu2)

                otherMenu.add(subMenu)
                otherMenu.add(item = new JCheckBoxMenuItem("\u0623\u0646\u0642\u0631\u0020\u05ea\u05dc\u05d7\u05e5"))
                item.addActionListener(this)
                otherMenu.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
                otherMenu.addSeparator()
                ButtonGroup buttonGroup = new ButtonGroup()
                otherMenu.add(item = new JRadioButtonMenuItem("\u0631\u0627\u062f\u064a\u0648\u0020\u05e8\u05d3\u05d9\u05d5"))

                item.addActionListener(this)
                buttonGroup.add(item)
                otherMenu.add(item = new JRadioButtonMenuItem("\u0631\u0627\u062f\u064a\u0648\u0020\u05e8\u05d3\u05d9\u05d5"))
                item.addActionListener(this)
                item.setFont(new Font("Lucida sans Regular",Font.PLAIN,14))
                buttonGroup.add(item)
                otherMenu.addSeparator()
                otherMenu.add(item = new JMenuItem("",
                                            new ImageIcon("image.gif")))
                item.addActionListener(this)

                add(fileMenu)
                add(editMenu)
                add(otherMenu)
            }

            public void actionPerformed(ActionEvent event) {
                System.out.println("Menu item [" + event.getActionCommand() +
                                   "] was pressed.")
            }

            public static void main(String s[]) {
                JFrame frame = new JFrame("Simple Menu Example")
                frame.setJMenuBar(new jMenuX())
                frame.pack()
                frame.setVisible(true)
            }
        }




        WorkAround:
        ======================================================================

        Name: rlT66838 Date: 04/12/2000


        java version "1.3.0rc2"
        java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
        Java HotSpot(TM) Client VM (build 1.3.0.rc-Y, mixed mode)

        When nesting submenus, null pointer exceptions occur. Although the example
        below nests 2 submenus, the error also occurs (though less reliably) with just
        a single submenu. I believe this is the same error as bug 4280243, but as that
        bug report was submitted on October 12, 1999 and has not yet been reviewed, I
        am submitting it again, this time against 1.3.0rc2.

        This is a very serious problem for building applications, and I would
        appreciate any suggestions of workarounds (other than never nesting JMenus).

          To trigger the null pointer exception, pull down the menu item "Menu Example",
        click on "SubMenu 2", then go back to the menu bar and try to pull down
        "Menu Example" again. This always triggers the error on my comptuer, but
        some variation of this may be required.

        This code is a simplified version of the code supplied in bug 4280243

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;


        class jMenuX extends JMenuBar{

            public jMenuX() {
                JMenu otherMenu = new JMenu("Menu Example");
                JMenu subMenu = new JMenu("SubMenu1");
                JMenu subMenu2 = new JMenu("SubMenu2");
                subMenu.add(subMenu2);
                subMenu2.add(new JMenuItem("Item"));
                otherMenu.add(subMenu);
                add(otherMenu);
               }

            public static void main(String s[]) {
                JFrame frame = new JFrame("Simple Menu Example");
                frame.setJMenuBar(new jMenuX());
                frame.pack();
                frame.setVisible(true);
           }
        }

        Here is the error message produced:

        Exception occurred during event dispatching:
        java.lang.NullPointerException: null pData
                at sun.awt.windows.WInputMethod.handleNativeIMEEvent(Native Method)
                at sun.awt.windows.WInputMethod.dispatchEvent(WInputMethod.java:275)
                at sun.awt.im.InputContext.dispatchEvent(InputContext.java:202)
                at sun.awt.im.InputMethodContext.dispatchEvent(InputMethodContext.java:1
        77)
                at java.awt.Component.dispatchEventImpl(Component.java:2529)
                at java.awt.Container.dispatchEventImpl(Container.java:1213)
                at java.awt.Component.dispatchEvent(Component.java:2499)
                at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451
        )
                at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:231
        8)
                at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2189)

                at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
                at java.awt.Container.dispatchEventImpl(Container.java:1200)
                at java.awt.Window.dispatchEventImpl(Window.java:912)
                at java.awt.Component.dispatchEvent(Component.java:2499)
                at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
                at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:10
        3)
                at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
                at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
        (Review ID: 103596)
        ======================================================================

        Name: tb29552 Date: 04/21/2000


        java version "1.3.0rc3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
        Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)

        I'm seeing this exception being thrown as I use jmenus that are used over a
        pjpanel that is placed in a jframe. I cannot provide any test code as time does
        not permit me to do so, and I have no real way of knowing *how* to reproduce
        this. Perhaps this exception might help:

        Exception occurred during event dispatching:
        java.lang.NullPointerException: null pData
        at sun.awt.windows.WInputMethod.handleNativeIMEEvent(Native Method)
        at sun.awt.windows.WInputMethod.dispatchEvent(WInputMethod.java:275)
        at sun.awt.im.InputContext.dispatchEvent(InputContext.java:202)
        at sun.awt.im.InputMethodContext.dispatchEvent
        (InputMethodContext.java:177)
        at java.awt.Component.dispatchEventImpl(Component.java:2529)
        at java.awt.Container.dispatchEventImpl(Container.java:1213)
        at java.awt.Component.dispatchEvent(Component.java:2499)
        at java.awt.LightweightDispatcher.retargetMouseEvent
        (Container.java:2451)
        at java.awt.LightweightDispatcher.trackMouseEnterExit
        (Container.java:2318)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2189)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
        at java.awt.Container.dispatchEventImpl(Container.java:1200)
        at java.awt.Window.dispatchEventImpl(Window.java:912)
        at java.awt.Component.dispatchEvent(Component.java:2499)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
        at java.awt.EventDispatchThread.pumpOneEvent
        (EventDispatchThread.java:103)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

        If I can be of any help (after someone has read this exception and may have
        some ideas), feel free to ask.
        (Review ID: 103978)
        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                naoto Naoto Sato
                vrosenmasunw Victor Rosenman (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: