Last active
January 11, 2016 23:42
-
-
Save raphw/ddca5d16a74a2d5663b4 to your computer and use it in GitHub Desktop.
Example of wrong type annotation indexing of type varaible bounds on recursive type variables by Java Core reflection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.bytebuddy.description; | |
import jdk.internal.org.objectweb.asm.TypeReference; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Foo<T, | |
S extends @Sample T, | |
U extends @Sample Runnable, | |
V extends @Sample String, | |
W extends @Sample List<?>, | |
X extends @Sample ArrayList<?>> { | |
public static void main(String[] args) { | |
System.out.println(Foo.class.getTypeParameters()[1].getAnnotatedBounds()[0].isAnnotationPresent(Sample.class)); | |
System.out.println(Foo.class.getTypeParameters()[2].getAnnotatedBounds()[0].isAnnotationPresent(Sample.class)); | |
System.out.println(Foo.class.getTypeParameters()[3].getAnnotatedBounds()[0].isAnnotationPresent(Sample.class)); | |
System.out.println(Foo.class.getTypeParameters()[4].getAnnotatedBounds()[0].isAnnotationPresent(Sample.class)); | |
System.out.println(Foo.class.getTypeParameters()[5].getAnnotatedBounds()[0].isAnnotationPresent(Sample.class)); | |
System.out.println(new TypeReference(285278208).getTypeParameterBoundIndex()); | |
System.out.println(new TypeReference(285344000).getTypeParameterBoundIndex()); | |
System.out.println(new TypeReference(285409280).getTypeParameterBoundIndex()); | |
System.out.println(new TypeReference(285475072).getTypeParameterBoundIndex()); | |
System.out.println(new TypeReference(285540352).getTypeParameterBoundIndex()); | |
} | |
} | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.TYPE_USE) | |
@interface Sample { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment