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

int overflow causes ArrayIndexOutOfBoundsException in MemoryHandler

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      (on XP)
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
      (on Linux)
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]
      Linux drskjones-a1 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      I am using a MemoryHandler to discard large numbers of LogRecords that are below a specified pushLevel. If MemoryHandler.publish() is called enough times, its internal counters (int variables) will overflow, resulting in the following exception:
      (running on XP / 5.0)
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -648
              at java.util.logging.MemoryHandler.publish(Unknown Source)
              at TestMemoryHandler.main(TestMemoryHandler.java:12)
      (running on Linux / 1.4.2)
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -648
              at java.util.logging.MemoryHandler.publish(MemoryHandler.java:160)
              at TestMemoryHandler.main(TestMemoryHandler.java:12)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I have provided executable test case source below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected all LogRecords to be discarded except the most recent 1000. No exceptions should occur. push() operations should not be required.
      ACTUAL -
      Exception occurs every time.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -648
              at java.util.logging.MemoryHandler.publish(MemoryHandler.java:160)
              at TestMemoryHandler.main(TestMemoryHandler.java:12)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.logging.*;

      public class TestMemoryHandler {
      public static void main(String args[]) throws Exception {
      ConsoleHandler console = new ConsoleHandler();
      MemoryHandler mem = new MemoryHandler(console, 1000, Level.WARNING);

      LogRecord record = new LogRecord(Level.INFO, "foo");

      // 2 x Integer.MAX_VALUE should cause the overflow
      for (int i=0; i < Integer.MAX_VALUE; i++) {
      mem.publish(record);
      mem.publish(record);
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Maybe I can override publish() and fix this bug?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                caustinsunw Calvin Austin (Inactive)
                Reporter:
                tbell Tim Bell
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: