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

ToolkitEventMulticaster must override AWTEventMulticaster.remove(EventListener)

XMLWordPrintable

    • 1.2fcs
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt
    • Not verified

      Because ToolkitEventMulticaster does not override remove(EventListener), the
      multicaster chain can be corrupted by inadvertant adds of AWTEventMulticaster
      instances, instead of ToolkitEventMulticaster instances.

      ToolkitEventMulticaster.remove(AWTEventListener, AWTEventListener)
        |
        |--> AWTEventMulticaster.removeInternal(EventListener, EventListener)
               |
               |--> AWTEventMulticaster.remove(EventListener)
                      |
                      |--> AWTEventMulticaster.addInternal(EventListener,
                              | EventListener)
                              |
                              |--> creates instance of AWTEventMulticaster and adds
                                   it to multicaster chain.

      Then, a subsequent call to TookitEventMulticaster.remove(AWTEventListener,
      AWTEventListener) can fail with a ClassCastException. This happens when
      we try to cast one of the AWTEventMulticaster instances into an
      AWTEventListener. The stack dump looks something like this (the linenumbers
      aren't quite right because they're from my internal build):

      Exception occurred during event dispatching:
      java.lang.ClassCastException: java.awt.AWTEventMulticaster
              at java.awt.Toolkit$ToolkitEventMulticaster.remove(Toolkit.java:1571)
              at java.awt.Toolkit.removeAWTEventListener(Toolkit.java:1534)
              at java.awt.LightweightDispatcher$2.run(Container.java:1847)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.awt.LightweightDispatcher.stopListeningForOtherDrags(Container.j
      ava:1844)
              at java.awt.LightweightDispatcher.trackMouseEnterExit(Container.java:179
      8)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1705)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:1645)
              at java.awt.Container.dispatchEventImpl(Container.java:1019)
              at java.awt.Window.dispatchEventImpl(Window.java:678)
              at java.awt.Component.dispatchEvent(Component.java:2286)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:258)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)

      The bug seems to happen when dragging in a dialog which is being disposed. See
      dpm for a reproducible test case.

      Since AWTEventMulticaster.addInternal(EventListener, EventListener) is static,
      we can't override it in ToolkitEventMulticaster. Instead, we will need to
      override remove(EventListener).

            feckssunw Fred Ecks (Inactive)
            dmendenhsunw David Mendenhall (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: