JDK-6565779 : NullPointerException thrown when dragging the tray icon and dropping it on a file dialog, XToolkit
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_10
  • CPU: sparc
  • Submitted: 2007-06-05
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b19Fixed
Related Reports
Relates :  
Description
Make sure a notification area is available on the gnome panel. Run the attached test. You will see a frame with many buttons and a tray icon will be added to the notification area. Click on 'set image' button. A file dialog will get opened. Leave it open. Click on the tray icon, drag it and drop it inside the FileDialog. You will see a flurry of NullPointer Exceptions being thrown on the console. 

This is reproducible only on XToolkit atleast since JDK6-b59d. Not reproducible on Win32. 

Here is the stack trace -
--------------------------
java.lang.NullPointerException
at java.awt.LightweightDispatcher.eventDispatched(Container.java:4077)
at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2339)
at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:2190)
at java.awt.TrayIcon.dispatchEvent(TrayIcon.java:665)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:177)
at java.awt.Dialog$1.run(Dialog.java:1032)
at java.awt.Dialog$2.run(Dialog.java:1078)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1076)
at java.awt.Component.show(Component.java:1406)
at java.awt.Component.setVisible(Component.java:1359)
at java.awt.Window.setVisible(Window.java:695)
at java.awt.Dialog.setVisible(Dialog.java:972)
at SystemTrayTest$ActionHandler.actionPerformed(SystemTrayTest.java:217)at java.awt.Button.processActionEvent(Button.java:388)
at java.awt.Button.processEvent(Button.java:356)
at java.awt.Component.dispatchEventImpl(Component.java:4365)
at java.awt.Component.dispatchEvent(Component.java:4195)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Comments
EVALUATION When the event (DRAGGED kind in this case) comes to Container.eventDispatched(), it is checked for getComponent(). But because the MouseEvent is the child of ComponentEvent, then null is returned: ComponentEvent.getComponent() method simply does: return (source instanceof Component) ? (Component)source : null; This only happens on Linux, not on Windows platform. Seem the behaviour of this use case is unspecified. I'm not sure that ignoring such kind of events would safe enought. However, the code in Container.eventDispatched(AWTEvent e) is only ready to accept Components as source of that event. The approach like ignoring nulls could hide some serious problems in the code in the future. Better way is to check the type of the source and skip event if it a TrayIcon instance. But that fact that this doesn't happen on Windows (but we still trying to fix shared code) shows that the real cause is in the TrayIconPeer class implementation.
03-07-2007

SUGGESTED FIX --- Container.java 2007-06-06 19:00:36.000000000 +0400 *************** *** 4116,4121 **** --- 4116,4126 ---- synchronized (nativeContainer.getTreeLock()) { Component srcComponent = srcEvent.getComponent(); + // check if event comes from TrayIcon, menu or any other + // non-Component object + if (srcComponent == null) { + return; + } // component may have disappeared since drag event posted // (i.e. Swing hierarchical menus)
06-06-2007

EVALUATION The exception is thrown from LightweightDispatcher code. When it proceeds some event, some checks like isShowing() are performed, however they are only available for Component instances. At the same time TrayIcon is not a component, so we should skip all the checks (and probably don't do any lw dispatching) for it (and probably for menus which are also not Components). An easy fix is listed in Suggested Fix. However, some more discussion/investigation may be required.
06-06-2007