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

compiler does not initialize a field of an anonymous inner class

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5.1, windows_nt

      Description



      Name: ouC59006 Date: 12/10/98


      JDK-1.2-V fails to pass new JCK test icls00709. Execution of reduced
      form of the test (see source code below) gives the following result:

      > java -version
      java version "1.2"
      Classic VM (build JDK-1.2-V, green threads, sunwjit)
      > javac Z.java
      > java Z
      0
      > cat Z.java
      public class Z {
      class IC {
      void someMethod() {}
      void anotherMethod() {
      new IC() {
      int m = 153;
      void someMethod() {
      System.out.println(m);
      }
      }.someMethod();
      }
      }

              public static void main(String[] s) {
      new Z().new IC().anotherMethod();
      }
      }
      >

      Note that JDK-1.2beta4-K successfully passes this test.
      The result does not depend on turning verifier or jit on or off.

      ======================================================================

      Name: gsC80088 Date: 03/09/99


      (Code to reproduce this bug can be found at the end of this message.)

      Instance variables do not seem to initialize themselves when using JDK 1.2. This problem does NOT exist in JDK 1.1.6 (I was not able to test against JDK 1.1.7).

      The following code will print

       null

      instead of

       This works!

      ------------------------------------------------

      public class jdk12bug
      {
        class Inner
        {
          public void printString()
            {
      System.out.println("X");
            }
        }

        Inner getInner()
          {
            return new Inner()
      {
      String s = new String("This works!");

      public void printString()
      {
      System.out.println(s);
      }
      };

          }

        void f()
          {
            Inner i = getInner();
            i.printString();
          }
        
        public static void main( String[] args )
          {
            jdk12bug j = new jdk12bug();
            j.f();
          }
      }
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              oulyankisunw Oleg Ulyankin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: