Bug 89937 - [1.5][compiler] Annotation attribute should not be able to reference field
Summary: [1.5][compiler] Annotation attribute should not be able to reference field
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-01 06:57 EST by David Audel CLA
Modified: 2005-05-27 10:46 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 David Audel CLA 2005-04-01 06:57:13 EST
build I20050331-2000

1) create p/Annot.java
package p;
public @interface Annot {
  int foo();
}

2) create p2/X.java
package p2;
import p.Annot;
public class X {
  @Annot(foo=zzz)
  static final int zzz = 0;
}
3) compile

jdtcore compiler found no error but javac found an error

p\X.java:4: illegal forward reference
    @Annot(foo=zzz)
               ^
1 error
Comment 1 David Audel CLA 2005-04-07 06:05:36 EDT
package p2;
import p.Annot;
public class X {
  void bar(){
    @Annot(foo=zzz)
    final int zzz = 0;
  }
}

With a local variable the behavior is the opposite. Eclipse refuse the code and
produce this error message: "The value for annotation attribute Annot.foo must
be a constant expression". Javac compile this code with no error.
Comment 2 Philipe Mulet CLA 2005-05-17 06:45:33 EDT
Added AnnotationTest#test145.
Initialization scope used during resolution needs to be told which field is
being initialized to probably recognize forward references.
Added support in 2 places:
- FieldBinding#getAnnotationTagbits()
- FieldDeclaration#resolve(MethodScope)

Fixed
Comment 3 Philipe Mulet CLA 2005-05-17 06:46:21 EDT
forgot to assign
Comment 4 Philipe Mulet CLA 2005-05-17 06:46:46 EDT
fixed
Comment 5 Maxime Daniel CLA 2005-05-27 10:04:08 EDT
Build I20050527-0010.
I get initial test case OK, comment #1 test case KO. Checked that javac quietly
accepts it, and we don't.
Philippe, would you please comment?
Comment 6 Frederic Fusier CLA 2005-05-27 10:46:29 EDT
I'll open a new bug for unfixed comment 1 test case...