-
Bug
-
Resolution: Fixed
-
P4
-
1.4.1, 6
-
b95
-
generic, sparc
-
generic, solaris_7
If components are added to Container using Container.add(Component comp, int
index), and index is not consecutive, IllegalArgumentException will be thrown.
Here is an example:
import java.awt.*;
public class ContainerAdd {
public static void main(String[] args) throws Exception {
Container c = new Container();
int[] values = {0, 1, 2, 3, 4, 8};
LWComponent comp = new LWComponent();
for(int i=0;i<values.length;i++) {
try {
c.add(new LWComponent(), values[i]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Unexpected ArrayIndexOutOfBoundsException, index=" + values[i]);
} catch (IllegalArgumentException e) {
System.out.println("IllegalArgumentExeption is thrown for index " + values[i]);
e.printStackTrace();
}
}
}
}
class LWComponent extends Component {
public LWComponent() {
}
}
Output in build 1.4.1-beta-b11 is:
IllegalArgumentExeption is thrown for index 8
java.lang.IllegalArgumentException: illegal component position
at java.awt.Container.addImpl(Container.java:605)
at java.awt.Container.add(Container.java:346)
at ContainerAdd.main(ContainerAdd.java:10)
"IllegalArgumentException - if index is invalid" this is unclear. User needs to know what indices are invalid.
This behavior needs to be documented.
.
index), and index is not consecutive, IllegalArgumentException will be thrown.
Here is an example:
import java.awt.*;
public class ContainerAdd {
public static void main(String[] args) throws Exception {
Container c = new Container();
int[] values = {0, 1, 2, 3, 4, 8};
LWComponent comp = new LWComponent();
for(int i=0;i<values.length;i++) {
try {
c.add(new LWComponent(), values[i]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Unexpected ArrayIndexOutOfBoundsException, index=" + values[i]);
} catch (IllegalArgumentException e) {
System.out.println("IllegalArgumentExeption is thrown for index " + values[i]);
e.printStackTrace();
}
}
}
}
class LWComponent extends Component {
public LWComponent() {
}
}
Output in build 1.4.1-beta-b11 is:
IllegalArgumentExeption is thrown for index 8
java.lang.IllegalArgumentException: illegal component position
at java.awt.Container.addImpl(Container.java:605)
at java.awt.Container.add(Container.java:346)
at ContainerAdd.main(ContainerAdd.java:10)
"IllegalArgumentException - if index is invalid" this is unclear. User needs to know what indices are invalid.
This behavior needs to be documented.
.
- duplicates
-
JDK-4687196 Container.add(Component, int) throws unspecified IllegalArgmentException
- Closed
- relates to
-
JDK-4290675 Focus Management Enhancements
- Closed