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

EventQueue.removeSourceEvents() throws NullPointerException

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: clC74495 Date: 03/31/98

      =20
      The method EventQueue.removeSourceEvents() which
      has the following line of code:

      =09if (entry.event.getSource().equals(source)) {

      fails if getSource() returns null, which is the case if the
      event has been unserialized.=A0

      Here is a test case:

      import java.awt.*;
      import java.io.*;
      import java.awt.event.*;

      public class QueueTest extends java.applet.Applet implements MouseListener{

        Button openB;

        /**
         * This event exists only for the purpose of setting its
         * source field to null. In our system, posting deserialized
         * events to the queue has this effect.
         */
        class TestEvent extends ActionEvent {
          TestEvent(Object src) {
            super(src, 10000, "none");
            source =3D null;
          }
        }
        =20

        /**
         * The main() function puts up a window with a button in it
         */
        public static void main(String args[]) {
          Frame f =3D new Frame("QueueTest");
          QueueTest queueTest =3D new QueueTest();
          queueTest.init();
          queueTest.start();


          queueTest.openB =3D new Button("make Java crash");
          queueTest.openB.addMouseListener(queueTest);
          f.add("Center", queueTest.openB);
          f.setSize(300, 300);
          f.show();
        }

        /**
         * This listener method posts an event with a null source to the event
         * queue and then removes the button from its parent. Removing the
         * button has the effect of calling java.awt.EventQueue.removeSourceEvent=
      s(),
         * which generates a NullPointerException because of the null source of
         * the event on the queue
         */
        public void mouseClicked(MouseEvent e) {
          TestEvent ev =3D new TestEvent(this);
          Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);
          openB.getParent().remove(openB);
        }

        public void mouseEntered(MouseEvent e) {;}
        public void mouseExited(MouseEvent e) {;}
        public void mousePressed(MouseEvent e) {
        }
        public void mouseReleased(MouseEvent e) {;}
      }

      --

      Here is a stack trace:

      java.lang.NullPointerException
              at java.awt.EventQueue.removeSourceEvents(EventQueue.java:189)
              at java.awt.Component.removeNotify(Component.java:2525)
              at java.awt.Container.removeNotify(Container.java:1147)
              at java.awt.Container.removeNotify(Container.java:1147)
              at java.awt.Container.removeNotify(Container.java:1147)
              at java.awt.Container.remove(Container.java:345)
              at java.awt.Container.remove(Container.java:384)
              at java.awt.Container.addImpl(Container.java:291)
              at java.awt.Container.add(Container.java:189)
              at WhiteBoard.ToolFrame.dockInWB(ToolFrame.java:178)
              at WhiteBoard.ToolFrame.setVisible(ToolFrame.java:133)
              at WhiteBoard.WhiteBoard.initialize(WhiteBoard.java:106)
              at WhiteBoard.WhiteBoard.startInFrame(WhiteBoard.java:117)
              at ncsa.habanero.Collobject.setFrame(Collobject.java:213)
              at ncsa.habanero.Collobject.<init>(Collobject.java:141)
              at ncsa.habanero.Sharable.instantiate(Sharable.java:170)
              at ncsa.habanero.AddCollobjectAction.act(AddCollobjectAction.java:1=
      18)
              at ncsa.habanero.Targetable.performAction(Targetable.java:125)
              at ncsa.habanero.tickets.Ticket.act(Ticket.java:165)
              at ncsa.habanero.granted.ActionGranted.dispatch(ActionGranted.java:=
      117)
              at ncsa.habanero.EventDispatchThread.dispatchEvent(EventDispatchThr=
      ead.j
      ava:196)
              at ncsa.habanero.EventDispatchThread.dispatchEvent(EventDispatchThr=
      ead.j
      ava:151)
              at ncsa.habanero.EventDispatchThread.run(EventDispatchThread.java:2=
      14)

      =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
      =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
      =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
      Carlos.Lucasius@Canada (Mar 31, 1998):
      Verified that this bug exists exactly as described.

      (Review ID: 26332)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            rkhansunw Robi Khan (Inactive)
            Reporter:
            clucasius Carlos Lucasius (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: