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

System classes lose static state on class unloading.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 1.1, 1.1.4, 1.2.0
    • Fix Version/s: 1.2.0
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      generic, other, x86, sparc
    • OS:
      generic, solaris_2.5.1, windows_nt
    • Verification:
      Not verified

      Description



      Name: mc57594 Date: 03/06/97


      IMPORTANT:
      this code works with jdk 1.0.2
      but it fails with jdk 1.1

      // FILE Singleton.java

      public class Singleton {
      protected static Singleton _Single = null;
      protected String _Value = "default";

      static {
      GetSingleton();
      }

      public static Singleton GetSingleton() {
         if (_Single == null) {
            _Single = new Singleton();
         }
         return(_Single);
      }

      protected Singleton()
      {
      System.err.println("creating");
      }

      public void Set(String s)
      {
         _Value = s;
      }

      public String toString()
      {
         return _Value;
      }

      protected void finalize() throws Throwable
      {
      System.err.println("finalizing");
      }
      }



      // FILE TestSingle.java

      import java.lang.*;

      class TestSingle extends Thread {
      public TestSingle()
      {
      }

      public void run()
      {
      Thread t = Thread.currentThread();
         try {
      t.sleep(20000);
         }
         catch(Exception es) {}
      }

      public static void main(String[] args)
      {
      TestSingle t1;

      try {
         Class c = Class.forName("Singleton");
         t1 = new TestSingle();
         t1.start();
         t1.join();
         t1.stop();
      }catch(Exception e){
      System.err.println(e);
      }
      }
      }

      running the command :
      java TestSingle
      the output is:
      creating
      finalizing

      the finalize() method is called about 1 second after
      the creation of the singleton, while the test thread is
      still running
      company - Elasis s.c.p.A. , email - ###@###.###
      ======================================================================

      [sheri.good@Eng 1997-03-26]
      This looks like the same bug. If it isn't, I can submit as a separate bug.


      Category: java
      Subcategory: runtime
      Bug/rfe/eou: comment
      Synopsis: Classes with a static reference to self, and no other references get garbage collected
      Severity Impact: (internal)
      Severity Functionality: (internal)
      Priority: (internal)
      Description: Access to the an instance of the class below is through its
      getInstance method so there are no references to the class
      to tell the gc not to collect it.

      public class Singleton {
       private static Singleton instance = null;
       public static Singleton getInstance () {
        if (instance == null) instance = new Singleton()
        return instance;
       }
       private Singleton () { }
       public void methodX() {}
       public void methodY() {}
       public void methodZ() {}
      }


        
      company - WorldStreet Corporation , email - ###@###.###
      Work around: Create a singleton registry class which has a reference to all
      singleton objects. Then you only have to keep a reference
      around for the registry. Alternatively, a public noGC flag
      could be added to Class which the runtime could check before
      gc'ing the class.
      Comments:
      customer_rec: new
      Company: other
      Employee:Edward Shea
      Release: jdk11
      Hardware Version: i586
      O/S version: win_nt_4.0
      User Role: D
      User Type: E
      Sun Contact: (internal)
      end_customer_rec:
      BUG_END

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sliangsunw Sheng Liang (Inactive)
              Reporter:
              mchamnessunw Mark Chamness (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: