Bug 9837 - Inconsistent behavior when compiling from source or using binaries for constant expressions
Summary: Inconsistent behavior when compiling from source or using binaries for consta...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-14 12:18 EST by Olivier Thomann CLA
Modified: 2002-02-19 07:54 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2002-02-14 12:18:33 EST
Using 228,

[public class Base {
  public final short CONSTANT = 14;
}]

[public class Derived extends Base {
	public short function(short i) {
		switch (i) {
			case CONSTANT :
				return 20;
		}
		return 0;
	}
	public static void main(String argv[]) {
		System.out.print("OK");
	}
}
]

If you compile both classes from source, everything is ok. If you compile the 
Base class first, and then the Derived class using the Base.class file, you get:
1. ERROR in Derived.java (at line 4)
	case CONSTANT :
	     ^^^^^^^^
case expressions must be constant expressions

It should not be the case. Javac 1.3.1 and 1.4 compile that code fine. The only 
difference we have is that we don't generate a ConstantValue attribute for the 
field in Base.
If I replace the Base.class with the one from javac, then we compile the code 
finely. The bug is on the generation of the constant value attribute for the 
field in the Base class.
Comment 1 Olivier Thomann CLA 2002-02-14 12:23:10 EST
The fix is trivial. We generate the Constant Value attribute only if the field 
binding is static. I remove this check and it works fine.
In fact if the field is non-static, the constant value attribute is silenlty 
ignored by the VM, but can be generated to tag the field as being constant.
I will release it as soon as I run all compiler tests.
Comment 2 Olivier Thomann CLA 2002-02-14 17:23:02 EST
Fixed and released in HEAD