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

More unexpected inner class behaviour

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.1
    • tools
    • x86
    • windows_2000



      Name: gm110360 Date: 04/07/2003


      FULL PRODUCT VERSION :
      Runtime version:

      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      Inner classes may give unexpected results. Besides, compiling
      with different JDKs (JDK1.2.2_014 vs JDK1.4.1_02) lead to
      classes that behave differently on a single JVM.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile source code: javac Strange.java
      2. Run Strange.main: java Strange

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      We expect:

      1. The same output for b1 and b2
      2. The output true in both cases. Although init is called
         by the parent constructors for both inner classes
         the Java specification says nothing about the variables
         b1 and b2. Especially it is NOT assumed they are class variables
         of the inner classes
        
      So we would expect:

         java Strange
         b1: true
         b2: true
      Depends on the JDK version used to compile the class Strange:

      If compiled with JDK-1.2.2_014:
      D:\JAVA\jdk1.2.2\bin\javac Strange.java
      D:\JAVA\j2sdk1.4.1_02\bin\java Strange
      b1: false
      b2: false

      If compiled with JDK-1.4.1_02:
      D:\JAVA\j2sdk1.4.1_02\bin\javac Strange.java
      D:\JAVA\j2sdk1.4.1_02\bin\java Strange
      b1: false
      b2: true



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      abstract class Strange {

         Strange() {
            init();
         }

         abstract void init();

         public static void main(String[] args) {

            boolean a = true;
            final boolean b1 = a;

      new Strange() {
      void init() {
      System.out.println("b1: " + b1);
      }
            };

            final boolean b2 = true;

      new Strange() {
      void init() {
      System.out.println("b2: " + b2);
      }
            };
         }
      }


      ---------- END SOURCE ----------
      (Review ID: 183414)
      ======================================================================

            gafter Neal Gafter (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: