JDK-6811674 : Container.setComponentZOrder throws NPE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2009-03-02
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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 b55Fixed
Related Reports
Relates :  
Description
Any test with call to setComponentZOrder throws NPE, the stack is

java.lang.NullPointerException
        at sun.awt.X11.XWindow.initGraphicsConfiguration(XWindow.java:169)
        at sun.awt.X11.XComponentPeer.updateGraphicsData(XComponentPeer.java:1566)
        at java.awt.Component.setGraphicsConfiguration(Component.java:1035)
        at java.awt.Container.removeDelicately(Container.java:509)
        at java.awt.Container.setComponentZOrder(Container.java:711)
        at Test$4.mousePressed(Test.java:593)
        at java.awt.Component.processMouseEvent(Component.java:6247)
        at java.awt.Component.processEvent(Component.java:6015)
        at java.awt.Button.processEvent(Button.java:380)
        at java.awt.Component.dispatchEventImpl(Component.java:4610)
        at java.awt.Component.dispatchEvent(Component.java:4436)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:286)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)

Introduced by the changes in Container.removeDelicately() for 6804747.

              comp.parent = null;
+             comp.setGraphicsConfiguration(null);
              component.remove(index);
The regression test java/awt/Container/ZOrder can be used to reproduce the failure.

Comments
SUGGESTED FIX --- old/src/share/classes/java/awt/Container.java 2009-03-02 13:06:29.000000000 +0300 +++ new/src/share/classes/java/awt/Container.java 2009-03-02 13:06:28.000000000 +0300 @@ -506,7 +506,9 @@ adjustDescendants(-(comp.countHierarchyMembers())); comp.parent = null; - comp.setGraphicsConfiguration(null); + if (needRemoveNotify) { + comp.setGraphicsConfiguration(null); + } component.remove(index); invalidateIfValid();
02-03-2009

EVALUATION Setting the GC to null via Component.setGraphicsConfiguration() should only be done when the peer of the component is removed: the removeDelicately() method should check the value of needRemoveNotify boolean flag before nullifying the GC. Generally, the GC should not be null when the peer exists.
02-03-2009