-
Backport
-
Resolution: Fixed
-
P3
-
None
-
b26
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)
...
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)
...
- backport of
-
JDK-6690791 Even more ClassCasetException with TrayIcon
- Resolved