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

Array from getDeclaredClasses causes JVM crash (SIGSEGV)

XMLWordPrintable

    • generic, x86
    • generic, windows_nt



      Name: tb29552 Date: 12/16/98


      /*
      Hi,

      I had been using jdk1.1.6 on NT4.0 and just installed jdk1.2rc2, and
      was disheartened to find systems that were working fine on 1.1.6
      caused the JVM of jdk1.2rc2 to crash into Dr.Watson when introspecting
      on classes.

      I've narrowed it down as far as finding a small example that
      consistently crashes. Invoking the toString() method on the Class[]
      array returned by Class.getDeclaredClasses() causes a crash;
      strangely, constructing an array with the same type and contents does
      not cause the crash, nor does the array returned by Class.getClasses().

      Here's example code:
      ......................................................................
      */
      public class ReflectNestedClass {
          public static void main(String[] args) {
              try {
                  Class[] myArray = (new Class[] {
                      B.class, C.class
                  });
                  System.out.println("my Array:");
                  print(myArray);

                  Class[] getClassesArray = ReflectNestedClass.class.getClasses();
                  System.out.println("getClasses Array:");
                  print(getClassesArray);

                  Class[] getDeclArray = ReflectNestedClass.class.getDeclaredClasses();
                  System.out.println("getDeclaredClasses Array:");
                  print(getDeclArray);

                  System.out.println("End.");
              }
              catch(Throwable e) {
                  e.printStackTrace();
              }
          }
          public static void print(Class[] array) {
              System.out.println(" length: " + array.length);
              System.out.flush();
              for (int i = 0; i < array.length; i++) {
                  System.out.println(" elt[" + i + "]: " + array[i]);
                  System.out.flush();
              }
              // jvm crashes on getDeclArray.toString() here
              System.out.println(" array: " + array);
              System.out.flush();
          }
          // field
          C c = new C();
          // nested classes
          public static class B {
          }
          public class C {
          }
      }
      /*
      ......................................................................

      Below is the trace output: Note that the program never prints out
      the "array:" line for the getDeclaredClasses array; right at this
      point the "Dr.Watson" dialog box appears saying

                        An application error has occurred
                 and an application error log is being generated.

                                     java.exe
          Exception: access violation (0xc0000005), Address: 0x5045f653

      I've included the jdb error message in case it is of any help, but it
      looks to me like it's just complaining that the java.exe process died
      and disappeared. Running it with java.exe looks the same without the
      jdb error message.

      ......................................................................
      Microsoft(R) Windows NT(TM)
      (C) Copyright 1985-1996 Microsoft Corp.

      d:\caroma\JavaTests>\devTools\jdk1.2rc2\bin\javac ReflectNestedClass.java
      \devTools\jdk1.2rc2\bin\javac ReflectNestedClass.java

      d:\caroma\JavaTests>\devTools\jdk1.2rc2\bin\jdb ReflectNestedClass
      \devTools\jdk1.2rc2\bin\jdb ReflectNestedClass
      Initializing jdb...
      0xae:class(ReflectNestedClass)
      > run
      run ReflectNestedClass
      running ...
      main[1] my Array:
        length: 2
        elt[0]: class ReflectNestedClass$B
        elt[1]: class ReflectNestedClass$C
        array: [Ljava.lang.Class;@c889adb6
      getClasses Array:
        length: 2
        elt[0]: class ReflectNestedClass$B
        elt[1]: class ReflectNestedClass$C
        array: [Ljava.lang.Class;@cec9adb6
      getDeclaredClasses Array:
        length: 2
        elt[0]: class ReflectNestedClass$B
        elt[1]: class ReflectNestedClass$C

      Fatal exception: java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read
      java.net.SocketException: Connection reset by peer: JVM_recv in socket input stream read
              at java.net.SocketInputStream.socketRead(Native Method)
              at java.net.SocketInputStream.read(Compiled Code)
              at java.io.BufferedInputStream.fill(Compiled Code)
              at java.io.BufferedInputStream.read(Compiled Code)
              at java.io.FilterInputStream.read(FilterInputStream.java:73)
              at sun.tools.debug.AgentIn.run(Compiled Code)
              at java.lang.Thread.run(Thread.java:479)

      ReflectNestedClass exited

      d:\caroma\JavaTests>
      ......................................................................

      My uninformed guess is that some native code used by
      getDeclaredMethods() fails to initialize the array correctly, so the
      toString() method gets led to non-existent memory by a stray pointer.

      Hope you can fix this one before the final release, as it wouldn't be
      good to have to be careful when introspecting. This kind of bug
      behavior is what java was supposed to avoid.

      Cheers,

      CarlManning

      */

      (Review ID: 47223)
      ======================================================================

            apalanissunw Anand Palaniswamy (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: