Last active
July 22, 2019 20:44
-
-
Save raphw/c5d6222b990573aaeaf4571aad3a7fa3 to your computer and use it in GitHub Desktop.
Fix for JDK-8202469 and JDK-8202473
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 sample; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.TYPE_USE) | |
public @interface TypeAnnotation { | |
int value(); | |
} |
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
Index: src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java (revision 55752:8ae33203d600a7c9f9b2be9b31a0eb8197270ab1) | |
+++ src/java.base/share/classes/sun/reflect/annotation/TypeAnnotationParser.java (revision 55752+:8ae33203d600+) | |
@@ -276,11 +276,21 @@ | |
// index 1. | |
if (bounds.length > 0) { | |
Type b0 = bounds[0]; | |
- if (!(b0 instanceof Class<?>)) { | |
- startIndex = 1; | |
- } else { | |
- Class<?> c = (Class<?>)b0; | |
- if (c.isInterface()) { | |
+ if (!(b0 instanceof TypeVariable<?>)) { | |
+ if (b0 instanceof Class<?>) { | |
+ Class<?> c = (Class<?>) b0; | |
+ if (c.isInterface()) { | |
+ startIndex = 1; | |
+ } | |
+ } else if (b0 instanceof ParameterizedType) { | |
+ ParameterizedType p = (ParameterizedType) b0; | |
+ Type r = p.getRawType(); | |
+ if (!(r instanceof Class<?>)) { | |
+ throw new AnnotationFormatError("Unexpected raw type: " + r); | |
+ } else if (((Class<?>) r).isInterface()) { | |
+ startIndex = 1; | |
+ } | |
+ } else { | |
startIndex = 1; | |
} | |
} | |
@@ -295,10 +305,11 @@ | |
l.add(t); | |
} | |
} | |
+ TypeAnnotation[] annon = l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY); | |
res[i] = AnnotatedTypeFactory.buildAnnotatedType(bounds[i], | |
AnnotatedTypeFactory.nestingForType(bounds[i], loc), | |
- l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), | |
- candidates.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), | |
+ annon, | |
+ annon, | |
(AnnotatedElement)decl); | |
} | |
return res; |
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 sample; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.AnnotatedType; | |
import java.lang.reflect.TypeVariable; | |
import java.util.ArrayList; | |
public class TypeVariableParameterizedNonInterfaceBound<U extends @TypeAnnotation(0) ArrayList<?>> { | |
public static void main(String[] args) { | |
TypeVariable<Class<TypeVariableParameterizedNonInterfaceBound>>[] variables = TypeVariableParameterizedNonInterfaceBound.class.getTypeParameters(); | |
TypeVariable<Class<TypeVariableParameterizedNonInterfaceBound>> variable = variables[0]; | |
AnnotatedType[] bounds = variable.getAnnotatedBounds(); | |
AnnotatedType bound = bounds[0]; | |
Annotation[] annotations = bound.getAnnotations(); | |
assert annotations.length == 1; | |
} | |
} |
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 sample; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.AnnotatedParameterizedType; | |
import java.lang.reflect.AnnotatedType; | |
import java.lang.reflect.TypeVariable; | |
import java.util.List; | |
import java.util.concurrent.Callable; | |
public class TypeVariableTwoBoundsSample<U extends Callable<@TypeAnnotation(0) ?> & List<@TypeAnnotation(1) ?>> { | |
public static void main(String[] args) { | |
TypeVariable<Class<TypeVariableTwoBoundsSample>>[] variables = TypeVariableTwoBoundsSample.class.getTypeParameters(); | |
TypeVariable<Class<TypeVariableTwoBoundsSample>> variable = variables[0]; | |
assert variable.getAnnotations().length == 0; | |
AnnotatedType[] bounds = variable.getAnnotatedBounds(); | |
for (int i = 0; i < 2; i++) { | |
AnnotatedType bound = bounds[i]; | |
AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) bound; | |
assert parameterizedType.getAnnotations().length == 0; | |
AnnotatedType[] actualTypeArguments = parameterizedType.getAnnotatedActualTypeArguments(); | |
Annotation[] annotations = actualTypeArguments[0].getAnnotations(); | |
assert annotations.length == 1; | |
assert annotations[0] instanceof TypeAnnotation && ((TypeAnnotation) annotations[0]).value() == i; | |
} | |
} | |
} |
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 sample; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.AnnotatedParameterizedType; | |
import java.lang.reflect.AnnotatedType; | |
import java.lang.reflect.TypeVariable; | |
import java.util.concurrent.Callable; | |
public class TypeVariableTwoDeclarationsSample<U extends Callable<@TypeAnnotation(0) ?>, V extends Callable<@TypeAnnotation(1) ?>> { | |
public static void main(String[] args) { | |
TypeVariable<Class<TypeVariableTwoDeclarationsSample>>[] variables = TypeVariableTwoDeclarationsSample.class.getTypeParameters(); | |
for (int i = 0; i < 2; i++) { | |
TypeVariable<Class<TypeVariableTwoDeclarationsSample>> variable = variables[i]; | |
assert variable.getAnnotations().length == 0; | |
AnnotatedType[] bounds = variable.getAnnotatedBounds(); | |
AnnotatedType bound = bounds[0]; | |
assert bound.getAnnotations().length == 0; | |
AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) bound; | |
AnnotatedType[] actualTypeArguments = parameterizedType.getAnnotatedActualTypeArguments(); | |
Annotation[] annotations = actualTypeArguments[0].getAnnotations(); | |
assert annotations.length == 1; | |
assert annotations[0] instanceof TypeAnnotation && ((TypeAnnotation) annotations[0]).value() == i; | |
} | |
} | |
} |
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 sample; | |
import java.lang.annotation.Annotation; | |
import java.lang.reflect.AnnotatedType; | |
import java.lang.reflect.Type; | |
import java.lang.reflect.TypeVariable; | |
public class TypeVariableVariableBoundSample<U, V extends @TypeAnnotation(0) U> { | |
public static void main(String[] args) { | |
TypeVariable<Class<TypeVariableVariableBoundSample>>[] variables = TypeVariableVariableBoundSample.class.getTypeParameters(); | |
TypeVariable<Class<TypeVariableVariableBoundSample>> variable = variables[1]; | |
AnnotatedType[] bounds = variable.getAnnotatedBounds(); | |
AnnotatedType bound = bounds[0]; | |
Annotation[] annotations = bound.getAnnotations(); | |
assert annotations.length == 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment