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

static initializer ignores RunTimeException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.1.6
    • 1.1.5
    • hotspot
    • 1.1.6
    • generic
    • generic
    • Verified



        Name: dgC58589 Date: 01/16/98


        Hello,

        I ran into the following situation using JDK 1.1.3 on Solaris and
        1.1.4 on Windows. I used a static initializer to allocate a data
        structure. So far, so good, but I made an mistake in there which
        caused an array overflow.

        I didn't notice this at first, since the program continued to work. I
        have been able to reduce the situation context to the following small
        program:

        public class bug {
          private static String str = "foo";
          private static int[] x;

          public static void main(String[] argv) {
            System.out.println(str);
          }

          static {
            System.out.println("in static");
            x = new int[10];
            x[-10]=4711;
            str="bar";
          }
        }

        This gives me the following output:

        % java bug
        in static
        foo

        The program works however, i.e. an error message is printed if I put
        the main routine into a different class and just instantiate the class
        `bug'.

        Either the RuntimeException ArrayIndexOutOfBoundsException that should
        have been raised is not thrown or not correctly handled. The former
        would mean that I can access memory via illegal indices that shouldn't
        be in my hands, but I guess that in fact the latter case applies.

        BTW: VisualAge and kaffe didn't show this strange behaviour, i.e. they
        both halted the program with an error message.

        Yours
        Markus
        (Review ID: 23505)
        ======================================================================

              sliangsunw Sheng Liang (Inactive)
              dgrahamcsunw David Graham-cumming (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: