Community
Participate
Working Groups
The Java compiler is failing to notice a dependency on static final class variables. When the value of the variable is modified, classes that reference that value are not recompiled...and are using a stale value of the variable. Synopsis: Class2 defines a 'public static final long' class variable. Class1 uses that statically defined value. If Class1 is already compiled, and Class2 is modified, then the compiler does not notice the dependency, and fails to refresh Class1's compilation. Example: --------------Class1.java---------------------- public class Class1 { static public void main(String[] args) { System.out.println("Class1 thinks it is: " + Class2.A_MISSED_DEPENDENCY); new Class2().showMe(); } } --------------------Class2.java------------------ public class Class2 { public static final long A_MISSED_DEPENDENCY = 200; public void showMe() { System.out.println("Class2 thinks it is: " + A_MISSED_DEPENDENCY); } } ----------------------- Compile and execute Class1.main. The following results are shown: ----------------------- Class1 thinks it is: 100 Class2 thinks it is: 100 ----------------------- Now, modify the value of Class2.A_MISSED_DEPENDENCY to something else. (I changed it to 200.) Now save and compile Class2 (File | Save) and re-run the program. The following results will be shown: ------------------------ Class1 thinks it is: 100 Class2 thinks it is: 200 ------------------------ The compiler failed to detect the dependency that Class1 has on Class2, and did not recompile Class1. Class1 incorrectly used a stale value for Class2.A_MISSED_DEPENDENCY. Additional Info: 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)
Tried to reproduce but could not. The change was propagated fine. Greg: Which build are you using? Is Auto-build enabled or disabled (look at the preference Window->Preferences- >Workbench->Perform build automatically...)?
Forget that... screwed up. I can reproduce it now.
Fixed. The only case we missed was longs.
Kent - pls backport to 2.1 maintenance stream.
I did the backport to 2.1 stream.
Verified.
Verified. for 3.0M1.