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

Toolkit.removeAWTEventListener(AWTEventListener listener) works wrong

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      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

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: