United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6511815 NPE from XSelection.checkChange
JDK-6511815 : NPE from XSelection.checkChange

Details
Type:
Bug
Submit Date:
2007-01-10
Status:
Closed
Updated Date:
2011-05-19
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
client-libs
OS:
linux
Sub-Component:
java.awt
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0,5.0u10,6
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
Sometimes when using (6.0) development builds of the NetBeans IDE and invoking some drag-and-drop operation (in the Gnome environment on FC 6 Linux) I get an exception:

java.lang.NullPointerException
        at sun.awt.X11.XSelection.checkChange(XSelection.java:701)
        at sun.awt.X11.XSelection.access$200(XSelection.java:28)
        at sun.awt.X11.XSelection$SelectionEventHandler.dispatchEvent(XSelection.java:710)
        at sun.awt.X11.XToolkit.dispatchEvent(XToolkit.java:408)
        at sun.awt.X11.XToolkit.run(XToolkit.java:493)
        at sun.awt.X11.XToolkit.run(XToolkit.java:438)
        at java.lang.Thread.run(Thread.java:595)

The above is from 1.5.0_10 and arose from a D&D operation on a Java class in the Packages view.

                                    

Comments
SUGGESTED FIX

--- XSelection.java	2007-01-12 19:22:14.000000000 +0300
***************
*** 30,36 ****
  public class XSelection {
  
      /* Maps atoms to XSelection instances. */
!     private static final Hashtable table = new Hashtable();
      /* Prevents from parallel selection data request processing. */
      private static final Object lock = new Object();
      /* The property in which the owner should place the requested data. */
--- 30,36 ----
  public class XSelection {
  
      /* Maps atoms to XSelection instances. */
!     private static final Hashtable<XAtom, XSelection> table = new Hashtable<XAtom, XSelection>();
      /* Prevents from parallel selection data request processing. */
      private static final Object lock = new Object();
      /* The property in which the owner should place the requested data. */
***************
*** 113,119 ****
       * <code>null</code> if none exists.
       */
      static XSelection getSelection(XAtom atom) {
!         return (XSelection)table.get(atom);
      }
  
      /**
--- 113,119 ----
       * <code>null</code> if none exists.
       */
      static XSelection getSelection(XAtom atom) {
!         return table.get(atom);
      }
  
      /**
***************
*** 746,752 ****
          XSelection selection = getSelection(selectionAtom);
          if (selection != null) {
              selection.isSelectionNotifyProcessed = true;
!             selection.clipboard.checkChange(formats);
          }
      }
  
--- 746,754 ----
          XSelection selection = getSelection(selectionAtom);
          if (selection != null) {
              selection.isSelectionNotifyProcessed = true;
!             if (selection.clipboard != null) {
!                 selection.clipboard.checkChange(formats);
!             }
          }
      }
                                     
2007-01-12
EVALUATION

Here is a problematic code:

        XSelection selection = getSelection(selectionAtom);
        if (selection != null) {
            selection.isSelectionNotifyProcessed = true;
            selection.clipboard.checkChange(formats);
        }

it looks like sometime clipboard is null and we do not handle this (in this particular
place), all other places which work with clipboard check it for null.

So, it looks like we should also add the check here.
                                     
2007-01-12



Hardware and Software, Engineered to Work Together