Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4428316

Container.add(Component, int) incorrectly throws ArrayIndexOutOfBoundsException

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 03/21/2001



      Method public Component add(Component comp, int index)
      of class java.awt.Container can throw undocumented
      ArrayIndexOutOfBoundsException when component is added twice.

      Here is minimized test:
      import java.awt.*;

      public class Test2 {
          public static void main(String argv[]) {

              Panel p=new Panel();
              int[] values = {0,1};
              Canvas comp = new Canvas();
              for(int i=0;i<values.length;i++) {
                  System.out.println(values[i]);
                  p.add(comp,values[i]);
              }
          }
      }
      --- Output ---
      %java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b55)
      Java HotSpot(TM) Client VM (build 1.4beta-B55, mixed mode)
      %java Test2
      0
      1
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
              at java.lang.System.arraycopy(Native Method)
              at java.awt.Container.addImpl(Container.java:461)
              at java.awt.Container.add(Container.java:344)
              at Test2.main(Test2.java:11)

      ======================================================================

            rraysunw Richard Ray (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: