Bug 80014

Summary: @Retention(RetentionPolicy.RUNTIME) is ignored for annotations
Product: [Eclipse Project] JDT Reporter: Constantine Plotnikov <cap>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: blocker    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=427745
Whiteboard:

Description Constantine Plotnikov CLA 2004-12-02 10:19:19 EST
I'm using eclipse-SDK-I20041201-win32.zip.

Runtime retention policy does not seems to be implemented in the compiler. In
the provided test null should not be returned from getAnnotation() method. The
following line is printed:
"value = null"

When compiled by JDK 1.5, the following line is printed:
"value = @test.Attr(tst=-1)"

Also class files are different "RuntimeVisibleAnnotations" class file attribute
is used by JDK 1.5 and "RuntimeInvisibleAnnotations" by Eclipse. 

Note: unsafe cast in sample is done to avoid bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=80012.

------------------ test/Attr.java ------------------
package test;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Attr {
  public int tst() default -1;
}

------------------ test/TestCls.java ---------------
package test;
import java.lang.annotation.Annotation;
@Attr 
public class TestCls {
  public static void main(String args[]) {
  	Object e = TestCls.class.getAnnotation((Class<Annotation>)(Class)Attr.class);
  	System.out.println("value = "+e);
  }
}
Comment 1 Olivier Thomann CLA 2004-12-02 15:13:04 EST
Meta-annotations are not supported yet. For now, all annotations are generated
with the default retention policy which is CLASS. They end up as
RuntimeInvisibleAnnotations in the .class file.
Comment 2 Olivier Thomann CLA 2004-12-02 15:32:51 EST
*** Bug 80012 has been marked as a duplicate of this bug. ***
Comment 3 Constantine Plotnikov CLA 2004-12-03 01:20:46 EST
I suggest making all annotations runtime visible in the next integration version
by default if support for meta-annotations is not planned for it yet. If it is
done, annotations will become usable for tools that need annotations on the
classes in runtime until they are completely supported.
Comment 4 Olivier Thomann CLA 2004-12-03 16:00:47 EST
Fixed and released in HEAD.
Regression tests added AnnotationTest.test079-test084.
Comment 5 Olivier Thomann CLA 2004-12-03 16:39:10 EST
*** Bug 80010 has been marked as a duplicate of this bug. ***
Comment 6 Frederic Fusier CLA 2004-12-15 12:57:24 EST
Verified for 3.1 M4 using build I200412142000.