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

Toolkit.removeAWTEventListener(AWTEventListener listener) works wrong

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.5



      Name: dsC58869 Date: 11/11/98



      The method Toolkit.removeAWTEventListener(AWTEventListener listener) can not remove
      the twice added listener from receiving dispatched AWTEvents.

      ==== Here is the test demonstrating the bug ====
      import java.awt.*;
      import java.awt.event.*;

      public class Test {
          public static void main (String args[]) {
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      EventQueue systemQueue = toolkit.getSystemEventQueue();
      Component button = new Button("Button");
      DummyAWTEventListener al = new DummyAWTEventListener(button);

      // add twice
      toolkit.addAWTEventListener(al, AWTEvent.COMPONENT_EVENT_MASK);
      toolkit.addAWTEventListener(al, AWTEvent.COMPONENT_EVENT_MASK);
      // remove twice
      toolkit.removeAWTEventListener(al);
      toolkit.removeAWTEventListener(al);



      DummyAWTEvent awtEvent = new DummyAWTEvent(button,
      ComponentEvent.COMPONENT_FIRST);
      systemQueue.postEvent(awtEvent);
      try {
      Thread.sleep(2000);
      } catch (Exception e) {
      e.printStackTrace();
      }
      System.out.println(al.changed);
      System.out.println(al.changedtwice);
      if (!al.changed && !al.changedtwice) {
      System.out.println("OKAY");
      } else {
      System.out.println("Failed");
      }
      System.exit(0);
          }
      }

      class DummyAWTEventListener implements AWTEventListener {
          Object sync;
          public DummyAWTEventListener (Object obj) {
      sync = obj;
          }

          boolean changed = false;
          boolean changedtwice = false;
          public void eventDispatched(AWTEvent e){
      if(sync == e.getSource()) {
      if(changed) changedtwice = true;
      else changed = true;
      }
          }

      }
      class DummyAWTEvent extends AWTEvent {
          public DummyAWTEvent(Object source, int id) {
           super(source, id);
          }
      }

      ==== Here is the output of the test ====
      %java -fullversion
      java full version "JDK-1.2fcs-R"
      %java Test
      true
      false
      Failed

      ======================================================================
       Justification:
      The method should work properly

      ======================================================================

            mbronsonsunw Mike Bronson (Inactive)
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: