JDK-6589530 : HW/LW mixing code incorrectly handles insertion of components with the setComponentZOrder() method
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: OpenJDK6,6u12,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux,windows_xp
  • CPU: generic,x86
  • Submitted: 2007-08-06
  • Updated: 2012-03-22
  • Resolved: 2011-05-18
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 6 JDK 7 Other
6u12Fixed 7 b21Fixed OpenJDK6Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
The Container.setComponentZOrder(Component comp, int index) method may be used to insert components into a Container. In this case the oldIndex value that gets passed to the mixOnZOrderChanging() method is -1. This actually causes an exception with the following stack:

java.lang.ArrayIndexOutOfBoundsException: No such child: -1
	at java.awt.Container.getComponent(Container.java:307)
	at java.awt.Component.mixOnZOrderChanging(Component.java:9696)
	at java.awt.Container.setComponentZOrder(Container.java:713)
The following test reproduces the problem.

import java.awt.*;

public class test {
    public static void main(String[] args) {
        Container c = new Container();
        Button b = new Button("b");
        c.setComponentZOrder(b, 0);
    }
}

Comments
SUGGESTED FIX $ sccs diffs -C Container.java ------- Container.java ------- *** /tmp/sccs.OkhFmi 2007-08-08 11:53:20.000000000 +0400 --- Container.java 2007-08-07 17:43:01.000000000 +0400 *************** *** 713,719 **** addDelicately(comp, curParent, index); ! if (!peerRecreated) { comp.mixOnZOrderChanging(oldZindex, index); } } --- 713,726 ---- addDelicately(comp, curParent, index); ! // If the oldZindex == -1, the component gets inserted, ! // rather than it changes its z-order. ! if (!peerRecreated && oldZindex != -1) { ! // The new 'index' cannot be == -1. ! // It gets checked at the checkAdding() method. ! // Therefore both oldZIndex and index denote ! // some existing positions at this point and ! // this is actually a Z-order changing. comp.mixOnZOrderChanging(oldZindex, index); } }
06-08-2007

EVALUATION The effect happens because the mixOnZOrderChanging() method is not aware of such uncommon usage of the setComponentZOrder() method. To fix this, we should check the value of the oldIndex argument before passing it to the getComponent() method. If the oldIndex is equal to -1, then this is an insertion, and there's no need to call mixOnZOrderChanging(). The mixOnShowing() will correctly be invoked on the addNotify() and/or setVisible(true) invokations.
06-08-2007