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)
Test to reproduce is here:
https://swinghelper.dev.java.net/source/browse/swinghelper/src/java/org/jdesktop/swinghelper/tray/JXTrayIcon.java?view=markup
For some reason it is reproduced only on Linux machines
Run this demo and click the red icon in the tray area
You'll have -
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: JXTrayIcon1 cannot be cast to java.awt.Component
at javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:204)
at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:817)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2353)