JDK-7071166 : LayoutStyle.getPreferredGap() - IAE is expected but not thrown
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-07-26
  • Updated: 2013-04-22
  • Resolved: 2011-09-02
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 JDK 8
7u2 b06Fixed 8Fixed
Description
From LayoutStyle.getPreferredGap() spec: 
"Throws:
IllegalArgumentException - if position is not one of SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.EAST or SwingConstants.WEST"

But IllegalArgumentException not thrown! See mini-test (updated!):


import javax.swing.*;
import java.awt.*;

import static javax.swing.LayoutStyle.ComponentPlacement.RELATED;
import static javax.swing.SwingConstants.*;

public class GetPreferredGapTest {

    public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, IllegalAccessException, InstantiationException {

        for (UIManager.LookAndFeelInfo lookAndFeelInfo : UIManager.getInstalledLookAndFeels()) {
            UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
            LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
            System.out.println("LookAndFeel: " + lookAndFeel.getName());

            LayoutStyle layoutStyle = LayoutStyle.getInstance();
            System.out.println("LayoutStyle: " + layoutStyle);

            for (int position : new int[]{NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST, 123, -456}) {
                try {
                    layoutStyle.getPreferredGap(new JComponent() {}, new JComponent() {}, RELATED, position, new Container());
                    System.out.println("getPreferredGap(): Position " + position + " - No IAE!");
                } catch (IllegalArgumentException e) {
                    System.out.println("getPreferredGap(): Position " + position + " - IAE!");
                }
            }

            System.out.println();
        }
    }

}

Comments
EVALUATION We should add position checking into the getPreferredGap method
28-07-2011