Re: ArrayIndexOutOfBoundsException-Bug?

=?iso-8859-1?Q?Mathias_St=FCmpert?= wrote:
> I think I found a bug in ShapeControl.setShapes:
>
> int len = Math.max(shs.length, shapes.length);
> for (int i=0; i<len; i++) {
>   shapes[i] = shs[i];
> }
>
> That causes an ArrayIndexOutOfBoundsException in my app because the for
> loops to the max of the lengths of both arrays.

Looks like a bug to me, too.  This patch should take care of
that:

diff -u -3 -p -r1.20 ShapeControl.java
--- ShapeControl.java   7 Jan 2002 18:42:55 -0000       1.20
+++ ShapeControl.java   1 May 2002 16:33:17 -0000
@@ -101,9 +101,14 @@ public class ShapeControl extends Contro
          throws VisADException, RemoteException {
     if (shapeSet == null) return;
     if (shs != null && shs.length > 0) {
-      int len = Math.max(shs.length, shapes.length);
+      final int len = Math.min(shs.length, shapes.length);
       for (int i=0; i<len; i++) {
         shapes[i] = shs[i];
+      }
+      if (shapes.length > shs.length) {
+        for (int i=shs.length; i < shapes.length; i++) {
+          shapes[i] = null;
+        }
       }
     }
     changeControl(true);


  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: