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

finalize() calling native function results in JVM crash

XMLWordPrintable

    • generic
    • generic



      Name: dbT83986 Date: 05/14/99


      When a finalize() method calls a native function,
      the JVM can unload the native library before all
      the finalize() methods are called resulting in
      a crash.

      For this to occur the run finalizers on exit must
      be true:

      class HelloWorld
      {
              public HelloWorld()
              {
                      System.loadLibrary("hello");
              }

              public native void displayHelloWorld();

              protected void finalize()
              {
                      displayHelloWorld();
              }

              public static void main(String[] args)
              {
                      System.runFinalizersOnExit(true);
                      new HelloWorld().displayHelloWorld();
              }
      }

      The native function displayHelloWorld can be any
      function.

      It appears that the finalizer for the object that
      contains the native library reference is run before
      that finalizer for the HelloWorld object.
      (Review ID: 57246)
      ======================================================================

            Unassigned Unassigned
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: