Bug 80014 - @Retention(RetentionPolicy.RUNTIME) is ignored for annotations
Summary: @Retention(RetentionPolicy.RUNTIME) is ignored for annotations
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 80010 80012 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-02 10:19 EST by Constantine Plotnikov CLA
Modified: 2014-02-09 01:21 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.