United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7071166 LayoutStyle.getPreferredGap() - IAE is expected but not thrown
JDK-7071166 : LayoutStyle.getPreferredGap() - IAE is expected but not thrown

Details
Type:
Bug
Submit Date:
2011-07-26
Status:
Resolved
Updated Date:
2013-04-22
Project Name:
JDK
Resolved Date:
2011-09-02
Component:
client-libs
OS:
generic
Sub-Component:
javax.swing
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u2 (b06)

Related Reports
Backport:

Sub Tasks

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
                                     
2011-07-28



Hardware and Software, Engineered to Work Together