If components are added to Container using Container.add(Component comp, int
index), and index is not consecutive, IllegalArgumentException will be thrown.
This behavior needs to be documented.
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)
Another unspecified behavior is that if the same instance of Component
is added repeatly to the container, IllegalArgumentException is also
thrown from the second time this component is added to the Container.
index), and index is not consecutive, IllegalArgumentException will be thrown.
This behavior needs to be documented.
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)
Another unspecified behavior is that if the same instance of Component
is added repeatly to the container, IllegalArgumentException is also
thrown from the second time this component is added to the Container.
- duplicates
-
JDK-6449497 Clarify IAE thrown by Container.add(Component, int)
- Resolved
- relates to
-
JDK-4647973 spec for Container.remove() incomplete
- Resolved
-
JDK-6250592 It is not clear how to reproduce IllegalArgumentException in java.awt.Container.addImpl()
- Closed