JDK-2170881 : Remove AWT tree lock from Container methods: getComponent, getComponents, getComponentCount
  • Type: Backport
  • Backport of: JDK-6784816
  • Component: client-libs
  • Sub-Component: java.awt
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2008-12-18
  • Updated: 2011-01-19
  • Resolved: 2009-01-19
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
6u12 b04Fixed 7Fixed
Comments
SUGGESTED FIX Changes to Container.java: @@ -269,47 +269,52 @@ * @deprecated As of JDK version 1.1, * replaced by getComponentCount(). */ @Deprecated public int countComponents() { - synchronized (getTreeLock()) { + // This method is not synchronized under AWT tree lock. + // Instead, the calling code is responsible for the + // synchronization. See 6784816 for details. return component.size(); } - } /** * Gets the nth component in this container. * @param n the index of the component to get. * @return the n<sup>th</sup> component in this container. * @exception ArrayIndexOutOfBoundsException * if the n<sup>th</sup> value does not exist. */ public Component getComponent(int n) { - synchronized (getTreeLock()) { - if ((n < 0) || (n >= component.size())) { - throw new ArrayIndexOutOfBoundsException("No such child: " + n); - } + // This method is not synchronized under AWT tree lock. + // Instead, the calling code is responsible for the + // synchronization. See 6784816 for details. + try { return component.get(n); + } catch (IndexOutOfBoundsException z) { + throw new ArrayIndexOutOfBoundsException("No such child: " + n); } } /** * Gets all the components in this container. * @return an array of all the components in this container. */ public Component[] getComponents() { return getComponents_NoClientCode(); } // NOTE: This method may be called by privileged threads. // This functionality is implemented in a package-private method // to insure that it cannot be overridden by client subclasses. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! final Component[] getComponents_NoClientCode() { - synchronized (getTreeLock()) { + // This method is not synchronized under AWT tree lock. + // Instead, the calling code is responsible for the + // synchronization. See 6784816 for details. return component.toArray(EMPTY_ARRAY); } - } // getComponents_NoClientCode() /** * Determines the insets of this container, which indicate the size * of the container's border. * <p>
2009-01-13

EVALUATION See parent CR for evaluation.
2008-12-18