Community
Participate
Working Groups
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.
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.
Fixed and released in HEAD