JDK-8008082 : Type annotations on cast not reflected correctly by javap
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-02-13
  • Updated: 2014-02-06
  • Resolved: 2013-05-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b91Fixed
Related Reports
Relates :  
Relates :  
Description
The type annotations on a cast are not reflected in the output of javap unless the cast
is annotated with more the one annotation types. Repeating the same annotation is not
enough, however, two annotations with different retention policy is enough.

To reproduce, compile the following class and run javap, and observe the lack of
CAST type annotation for the fiels "not_ok".

Note: I'm filing the problem against javap, as it was uncovered in javap testing.
It' is likely, however, that the problem is at the classfile level.


import java.lang.annotation.*;
class Test {

    @Repeatable(As.class)
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.CLASS)
    @interface A {
        Class f() default int.class;
    }
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.CLASS)
    @interface As { A[] value(); }

    @Repeatable(Bs.class)
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.CLASS)
    @interface B {
        Class f() default int.class;
    }
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.CLASS)
    @interface Bs { B[] value(); }

    @Repeatable(Cs.class)
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.RUNTIME)
    @interface C {
        Class f() default int.class;
    }
    @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
    @Retention(RetentionPolicy.RUNTIME)
    @interface Cs { C[] value(); }
    static String so = "hello world";

    public @A Object not_ok = (@A @A String) Test.so;
    public @A Object ok = (@A @B String) Test.so;
    public @A Object also_ok = (@A @C String) Test.so;
}

Comments
Fix in tl/langtools through commit for JDK-8013852
15-05-2013

Original commit: http://hg.openjdk.java.net/type-annotations/type-annotations/langtools/rev/ac33d03e35b8
15-05-2013

Fixed in type-annotations forest
29-04-2013

@ignore: The following test contains 4 test cases which are affected because of this issue. langtools/test/tools/javap/output/RepeatingTypeAnnotations.java
27-04-2013

I agree that the root-cause of the problem is probably not in javap. However, I was not able to confirm that at the time of filing, and therefore filed it against the component exhibiting the symptoms.
15-02-2013

Since javap does not decompile code, it does not seem to make sense to file a bug against javap for this -- it has no direct way to report annos on a cast -- unless you're talking down at the byte code level -- are you? It would help to see an example of what you believe to be incorrect output from javap.
15-02-2013

I think this bug is related to https://jbs.oracle.com/bugs/browse/JDK-8005681 if not the same.
13-02-2013

It seems like it works with one annotation type on a cast but does not work when you make it repeatable. This case works: public @A Object ok = (@A String) Test.so;
13-02-2013