Bug 108263

Summary: [1.5][compiler] Constants initilialization doesn't work inside Annotation
Product: [Eclipse Project] JDT Reporter: David Audel <david_audel>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: kent_johnson, Olivier_Thomann
Version: 3.1   
Target Milestone: 3.1.1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Regression test none

Description David Audel CLA 2005-08-29 09:11:05 EDT
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
Comment 1 Olivier Thomann CLA 2005-08-29 14:56:55 EDT
If the annotation is converted to an interface, it works fine.
Comment 2 Olivier Thomann CLA 2005-08-29 16:10:26 EDT
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.
Comment 3 Olivier Thomann CLA 2005-08-29 17:00:00 EDT
Created attachment 26601 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2005-08-29 17:00:23 EDT
Created attachment 26602 [details]
Regression test
Comment 5 Olivier Thomann CLA 2005-08-30 08:03:01 EDT
All tests passed.
Comment 6 Olivier Thomann CLA 2005-08-30 10:23:13 EDT
This could be a candidate for 3.1.1.
Comment 7 Philipe Mulet CLA 2005-09-06 05:28:11 EDT
Why does the patch remove the check for annotation type constructor ? These are
still forbidden.
Comment 8 Philipe Mulet CLA 2005-09-06 05:40:30 EDT
Ok, it actually moves it elsewhere, to match the interface handling. This is
good, though not mandated by this defect.
Comment 9 Philipe Mulet CLA 2005-09-06 07:07:28 EDT
+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.
Comment 10 Philipe Mulet CLA 2005-09-06 07:09:08 EDT
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.
Comment 11 Philipe Mulet CLA 2005-09-06 07:45:22 EDT
Fixed. Added AnnotationTest#test177, AnnotationDietRecoveryTest#test0010.
Updated impacted existing tests.

(did not touch BinaryTypeBinding for now)
Comment 12 David Audel CLA 2005-09-21 10:44:44 EDT
Verified in I20050921-0010 for 3.2M2
Comment 13 David Audel CLA 2005-09-26 12:04:47 EDT
Verified using M20050923-1430 for 3.1.1