Community
Participate
Working Groups
build I20050823-0800 + jdtcore head 1) create A.java public @interface A { public static final Integer foo = B.zzz; public static final int foo3 = B.zzz2; } class B { public static final Integer zzz = new Integer(0); public static final int zzz2 = 0; } 2) compile jdtcore compiler found one error "The annotation field A.foo must be initialized with a constant expression" and javac none
If the annotation is converted to an interface, it works fine.
According to the specs, there is no need to have a constant expression as the initialization of such a field. The field simply needs to be initialized. The treatement should be the same as the field for an interface. Such a field without an initialization should report the error: The blank final field ... may not have been initialized and not the error : The annotation field ... must be initialized with a constant expression I will attach a patch that makes the handling of annotations close to the one of interfaces.
Created attachment 26601 [details] Proposed fix
Created attachment 26602 [details] Regression test
All tests passed.
This could be a candidate for 3.1.1.
Why does the patch remove the check for annotation type constructor ? These are still forbidden.
Ok, it actually moves it elsewhere, to match the interface handling. This is good, though not mandated by this defect.
+1 for 3.1.1. Patch looks mostly just fine. Will integrate and adjust a little. Will also add test for recovery of local annotation type decl.
Kent - in BinaryTypeBinding constructor, why do we have only ? // TODO (kent) what about ANNOTATION_TYPE_DECL case ? if (binaryType.getKind() == IGenericType.INTERFACE_DECL) this.modifiers |= AccInterface; Feels like annotation type case is not handled. But, do we need this statement at all ? Modifiers should already contain the information I suppose.
Fixed. Added AnnotationTest#test177, AnnotationDietRecoveryTest#test0010. Updated impacted existing tests. (did not touch BinaryTypeBinding for now)
Verified in I20050921-0010 for 3.2M2
Verified using M20050923-1430 for 3.1.1