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

Static member gets null by java 1.1.4 (but not set by my app)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.4
    • hotspot
    • x86
    • windows_nt



      Name: joT67522 Date: 11/11/97


      The problem is very hard to reproduce, I tried
      with a small testcase but unfortunately the test
      case runs perfect.
      -) I have a class (Main) with a static instance of
         the application window. The member can only
         be set in one method. (initFrame)
      -) The method is called in only 2 situations in
         my application. Either from main or from a
         settings view.
      -) With JDK 1.1.4 when calling the method for the
         2nd time (the member is already set and never
         reset) it suddenly is null.
      -) When I switch back to JDK 1.1.3 the code works
         correct without recompiling it. So I assume it
         is a problem of the virtual machine.

      Sample code (however this small sample works
      correct; just my complex APP has problems - but I
      was not able to reproduce it in a small sample).
      I could send you the full application; but where
      shall I send it to ???

      class Main
      {
        private static MyMainWindow myFrame=null;

        /**
         * only method to access myFrame !!!
         */
        public static initFrame()
        {
          if ( myFrame==null )
          {
      System.out.println( "not set ... initialising" );
            myFrame=new MyMainWindow();
            myFrame.show();
          }
          else
          {
      System.out.println( "set ... initialising" );
            myFrame.restore()
          }
        }

        /**
         * tests if the settings are correct, if yes it
         * directly opens the main window with initFrame
         * if no it first opens the settings view which
         * internally calls initFrame.
         */
        public static void main(String argv[])
        {
          "if ( settings ok )
          {
            initFrame();
          }
          else
          {
            openSettings(); // here myFrame is still null
          }
        }
      }

      class Settings extends Frame
      {
        // class logic is not important. In the class
        // there is the following method
        private void okButtonPressed()
        {
          // opens the frame window if not already open.
          Main.initFrame();
        }
      }

      Ok, above is the only code in my app. accessing
      the static variable. I made the following
      investigations:

      1) if I have bad settings everything is fine
         The frame is not initialized by main but
         by Settings:
         initFrame reports that the frame is null and
         creates a new frame window.

      2) if the setting are correct then
        2a) initFrame is called from the main method
            reports that myFrame is null and creates
            the main window. (The window remains open)
        2b) Now from the main window the settings are
            opened - the user presses ok and so
            initFrame is called again.

        Now initFrame reports that myFrame is NOT SET !!
        with Java 1.1.4. !!! and it opens another
        instance of MyMainWindow.

        2c) When I do 2b) again now initFrame reports
            that myFrame is set.

        With Java 1.1.3 2b) works as expected (initFrame
        says that myFrame is set and restores it).

      Hope my report is not too vague and you are
      taking it seriously. I still try to get a small
      testcase ... If I have you'll get it.

      Chris
      (Review ID: 19170)
      ======================================================================

            hongzh Hong Zhang
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: