It looks like javac omits the type_path structure for nested types in supertype and implemets targets. In the example below, when looking at GenericSub in javap I get this encoding of @Foo (Note that javap uses type_index and location differently from the vm spec):
RuntimeVisibleTypeAnnotations:
0: #18(): CLASS_EXTENDS, type_index=-1, location=[TYPE_ARGUMENT(0)]
as expected, but when looking at either Impl or SubInner I get:
RuntimeVisibleTypeAnnotations:
0: #15(): CLASS_EXTENDS, type_index=0
or
RuntimeVisibleTypeAnnotations:
0: #14(): CLASS_EXTENDS, type_index=-1
Note the missing type_path (location in javap) for the nesting, which I think table Table 4.7.20.2-E in the vm spec implies.
--- 8< ---
import java.lang.annotation.*;
import java.util.*;
import java.lang.reflect.*;
/*
* @test
*/
public class LostTypePath {}
class Super {}
class Sub extends @Foo Super {}
class Generic<A> {}
class GenericSub<B> extends Generic<@Foo B> {}
class Outer { public static class Inner {}}
class SubInner extends Outer . @Foo Inner {}
interface IOuter { public interface IInner {}}
class Impl implements IOuter . @Foo IInner {}
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface Foo {}
RuntimeVisibleTypeAnnotations:
0: #18(): CLASS_EXTENDS, type_index=-1, location=[TYPE_ARGUMENT(0)]
as expected, but when looking at either Impl or SubInner I get:
RuntimeVisibleTypeAnnotations:
0: #15(): CLASS_EXTENDS, type_index=0
or
RuntimeVisibleTypeAnnotations:
0: #14(): CLASS_EXTENDS, type_index=-1
Note the missing type_path (location in javap) for the nesting, which I think table Table 4.7.20.2-E in the vm spec implies.
--- 8< ---
import java.lang.annotation.*;
import java.util.*;
import java.lang.reflect.*;
/*
* @test
*/
public class LostTypePath {}
class Super {}
class Sub extends @Foo Super {}
class Generic<A> {}
class GenericSub<B> extends Generic<@Foo B> {}
class Outer { public static class Inner {}}
class SubInner extends Outer . @Foo Inner {}
interface IOuter { public interface IInner {}}
class Impl implements IOuter . @Foo IInner {}
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface Foo {}
- duplicates
-
JDK-8066967 Class.getAnnotatedSuperclass() does not correctly extract annotations
-
- Closed
-