Bug 36490 - Java compiler misses dependency on 'static final' class variables.
Summary: Java compiler misses dependency on 'static final' class variables.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 2.1.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-15 08:41 EDT by Greg Johnson CLA
Modified: 2003-06-10 10:22 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Johnson CLA 2003-04-15 08:41:40 EDT
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)
Comment 1 Kent Johnson CLA 2003-04-28 14:03:37 EDT
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...)?
Comment 2 Kent Johnson CLA 2003-04-28 14:09:58 EDT
Forget that... screwed up. I can reproduce it now.
Comment 3 Kent Johnson CLA 2003-04-28 14:54:46 EDT
Fixed.

The only case we missed was longs.
Comment 4 Philipe Mulet CLA 2003-04-29 05:46:56 EDT
Kent - pls backport to 2.1 maintenance stream.
Comment 5 Philipe Mulet CLA 2003-04-29 05:55:44 EDT
I did the backport to 2.1 stream.
Comment 6 David Audel CLA 2003-06-02 06:51:00 EDT
Verified.
Comment 7 David Audel CLA 2003-06-10 10:22:02 EDT
Verified. for 3.0M1.