JDK-4843796 : More unexpected inner class behaviour
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-04-07
  • Updated: 2003-04-08
  • Resolved: 2003-04-08
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION It appears when we compile the java code we get different byte code sizes for the different JDK's. Assigning to javac for further eval. Let me know if this bug belongs to some other group. ###@###.### 2003-04-08 This is a dup of 4030374. You can get the correct code by using -target 1.4. ###@###.### 2003-04-08
08-04-2003