JDK-6257333 : Method BorderLayout.getLayoutComponent(Container target, Object constraints) behaves unexpectedly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-04-19
  • Updated: 2017-05-16
  • Resolved: 2006-01-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 6
6 b67Fixed
Related Reports
Relates :  
Description
According to specification for java.awt.BorderLayput.getLayoutComponent(Container target, Object constraints)
passed target param is "the Container using this BorderLayout", so if container that does not use this layout is passed, then null is expected to be returned
-------------------------------------------------------------
Parameters:
    constraints - the desired absolute position, one of CENTER, one of NORTH, SOUTH, EAST, WEST
    target - the Container using this BorderLayout 
-------------------------------------------------------------
but actually component that was passed to method addLayoutComponent(Component comp, Object constraints) using the same constraints is returned 

Here is an example:
----- Test.java ---------------------------------------------
import javax.swing.*;
import java.awt.*;

public class Test {
    public static void main(String[] args) {
        final BorderLayout borderLayout = new BorderLayout();
        final Component componentToBeAdded = new JButton();
        borderLayout.addLayoutComponent(componentToBeAdded, BorderLayout.CENTER);
        final Component returnedComponent = borderLayout.getLayoutComponent(new JPanel(), BorderLayout.CENTER);
        System.out.println("returnedComponent = " + returnedComponent);
    }
}
----------------------------------------------------------
dmitry.bessonov@russia 2005-04-19 13:16:54 GMT

Comments
SUGGESTED FIX *** /tmp/geta18370 2005-11-22 14:00:41.000000000 +0300 --- BorderLayout.java 2005-11-22 14:00:15.000000000 +0300 *************** *** 531,537 **** * <code>EAST</code>, <code>WEST</code> * @param target the <code>Container</code> using this <code>BorderLayout</code> * @return the component at the given location, or </code>null</code> if ! * the location is empty * @exception IllegalArgumentException if the constraint object is * not one of the five specified constants * @exception NullPointerException if the target parameter is null --- 531,538 ---- * <code>EAST</code>, <code>WEST</code> * @param target the <code>Container</code> using this <code>BorderLayout</code> * @return the component at the given location, or </code>null</code> if ! * the location is empty or if target don't use ! * this {@code BorderLayout} * @exception IllegalArgumentException if the constraint object is * not one of the five specified constants * @exception NullPointerException if the target parameter is null *************** *** 539,544 **** --- 540,550 ---- * @since 1.5 */ public Component getLayoutComponent(Container target, Object constraints) { + // fix 6257333 : Method BorderLayout.getLayoutComponent(Container target, + // Object constraints) behaves unexpectedly + if (target.getLayout() != this){ + return null; + } boolean ltr = target.getComponentOrientation().isLeftToRight(); Component result = null;
22-11-2005

EVALUATION There is no any sort of check if target Container is assigned with current instance of BorderLayout in code below. Seems that first parameter is never in use: .... public Component getLayoutComponent(Container target, Object constraints) { boolean ltr = target.getComponentOrientation().isLeftToRight(); Component result = null; .... ###@###.### 2005-04-22 11:19:54 GMT
22-04-2005