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

Even more ClassCasetException with TrayIcon

    XMLWordPrintable

Details

    • Backport
    • Resolution: Fixed
    • P3
    • 6u10
    • None
    • client-libs

    Description

      There is one more place when we unsafely cast MouseEvent.getSource() to Component
      and get ClassCastException is the source of the event is TrayIcon (TrayIcon doesn't extend awt.Component).

      The test case:
      ===== Source Begin =====
      import javax.swing.*;
      import java.awt.event.MouseEvent;

      public class bug6690791 {
          public static void main(String[] args) throws Exception {
              MouseEvent me = new MouseEvent(new JLabel(), MouseEvent.MOUSE_CLICKED,
                      System.currentTimeMillis(), MouseEvent.ALT_MASK,
                      10, 10, 100, 100, 1, false, MouseEvent.BUTTON1);
              me.setSource(new Object());
              MenuSelectionManager.defaultManager().processMouseEvent(me);
          }
      }
      ===== Source End =====

      If you run the test under 6u10, you will get the following exception:
      Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to java.awt.Component
      at javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:204)
      at bug6690791.main(bug6690791.java:42)
              ...

      Attachments

        Issue Links

          Activity

            People

              mlapshin Mikhail Lapshin (Inactive)
              mlapshin Mikhail Lapshin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: