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

Printed index incorrect for ArrayIndexOutOfBoundsException when compiled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.2_15
    • vm-legacy
    • None
    • generic
    • solaris_8

      Date: Mon, 28 Apr 2003 09:16:54 -0700 (PDT)
      From: Ross Knippel <###@###.###>
      Subject: Re: Exception Report Question
      To: ###@###.###
      Cc: ###@###.###
      MIME-Version: 1.0
      Content-MD5: KZ6yLhm3HKNV4SyAApm1sA==

      Yes, the printed array index seems incorrect when
      the method is compiled by the latest 1.2.2_15.
      It looks okay when interpreted.

      -ross

      ---- OutOfBounds.java -------------

      class DLinkNode {
        DLinkNode next;
        Object element;
        int field;
        DLinkNode() {}
      }

      class OutOfBounds {
        static DLinkNode anchor;
        static int elementCount;

        public Object[] toNativeArray ()
        {
          Object[] array = new Object[elementCount];
          DLinkNode node = anchor.next;
          int idx = 0;
          // loop until end of list
          while (node != anchor)
            {
      System.out.println("idx: "+idx+" field: "+node.field);
      array[idx++] = node.element;
      node = node.next;
            }
          return array;
        }
        
        public static void main(String[] args) {
          int allocCount = 100;
          DLinkNode last = null;
          anchor = last;
          for(int i = allocCount - 1; i >= 0 ; i--) {
            DLinkNode n = new DLinkNode();
            if (last == null) last = n;
            n.next = anchor;
            n.field = i;
            anchor = n;
          }
          last.next = anchor;
          elementCount = allocCount - 2; // force indexOutOfBounds
          System.out.println("Init done.");
          Object[] oa = new OutOfBounds().toNativeArray();
        }
      }

      > /files/ws/evm/build/solaris/bin/java OutOfBounds

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 <-----
              at OutOfBounds.toNativeArray(Compiled Code)
              at OutOfBounds.main(Compiled Code)
              
      > /files/ws/evm/build/solaris/bin/java -Djava.compiler=NONE OutOfBounds

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 98 <-----
              at OutOfBounds.toNativeArray(OutOfBounds.java:21)
              at OutOfBounds.main(OutOfBounds.java:41)

      > From: "Keith Melkild" <###@###.###>
      > To: ###@###.###
      > Subject: Exception Report Question
      > Date: Sat, 26 Apr 2003 18:33:30 -0500
      > MIME-Version: 1.0
      >
      > Hi,
      >
      > We are seeing this error periodically in 1.2.2 and I was wondering if anyone
      > could shed some light on this. This method is out of a DList collection
      > class that we wrote quite some time ago. Here's the question? How can the
      > method below be trying to access the element specified? It doesn't seem
      > possible. Yes, we could have the structure screwed up and flip the int, but
      > I would think this would result in the smallest negative number
      > (-2147483648) being reported. Could the element # being reported be bogus?
      >
      > Thanks,
      > Keith
      >
      >
      > java.lang.ArrayIndexOutOfBoundsException: -810172480
      > at com.nortelnetworks.ims.foundation.collection.DList.toNativeArray(Compiled
      > Code)
      > at
      > com.nortelnetworks.ims.mw.imdb.tables.IMWatchersTable.querySvcPkgWatchers(Co
      > mpiled Code)
      > public Object[] toNativeArray ()
      > {
      > Object[] array = new Object[elementCount];
      > DLinkNode node = anchor.next;
      > int idx = 0;
      > // loop until end of list
      > while (node != anchor)
      > {
      > array[idx++] = node.element;
      > node = node.next;
      > }
      > return array;
      > }
      >

            chrisphi Chris Phillips
            rknippelsunw Ross Knippel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: