axistudio / interfascia

Automatically exported from code.google.com/p/interfascia
Other
0 stars 0 forks source link

IndexOutOfBoundsException in GUIController.remove():110 #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The problem:

You add three buttons to a controller. Then try and remove them in the order 
they were added. 
You get an exception thrown. If you remove the buttons in the opposite order 
that they were 
added, it works fine.

To reproduce:

c = new GUIController(this);
b1 = new IFButton("Button1", 10, 10);
b2 = new IFButton("Button2", 10, 40);
b3 = new IFButton("Button3", 10, 70);

c.add(b1);
c.add(b2);
c.add(b3);

c.remove(b1);

/*Exception thrown */

The cause:

Line 110 of GUIController.java is currently:
System.arraycopy(contents, componentIndex + 1, contents, componentIndex, 
numItems);

However, that will always fail, as numItems is always larger than the segment 
we are trying to 
copy (it can be at most numItems - 1 items long). This causes an 
IndexOutOfBoundsException.

The solution:
Line 110 of GUIController.java should be:
System.arraycopy(contents, componentIndex + 1, contents, componentIndex, 
numItems - 
(componentIndex + 1));

The length of the array segment to copy is numItems - (componentIndex + 1) 
instead of 
numItems.

All line numbers and file names are from SVN revision 26.

Original issue reported on code.google.com by hole...@gmail.com on 22 Aug 2007 at 4:48

GoogleCodeExporter commented 9 years ago
Fixed. Adding the code to reproduce the bug to the test suite.

Original comment by supersta...@gmail.com on 20 Apr 2008 at 8:22

GoogleCodeExporter commented 9 years ago

Original comment by supersta...@gmail.com on 20 Apr 2008 at 8:24