JDK-8202473 : (ann) A type variable with multiple bounds does not correctly place type annotation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8,9,10,11
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-04-30
  • Updated: 2020-09-29
  • Resolved: 2019-09-09
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 16
16 b17Resolved
Related Reports
Duplicate :  
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
If two type annotations are placed on two bounds, the reflection API does not consider the bound's index such that an exception is thrown when the reflection API parses the annotations. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the example code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception is thrown and the type annotations are returned correctly.
ACTUAL -
An exception is thrown.

---------- BEGIN SOURCE ----------
public class Foo<T extends Callable<@Foo.SampleTypeAnnotation ?> & List<@Foo.SampleTypeAnnotation ?>> {

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE_USE)
    @interface SampleTypeAnnotation { }

    public static void main(String[] args) throws Exception {
        TypeVariable<Class<Foo>>[] variables = Foo.class.getTypeParameters();
        AnnotatedType[] bounds = variables[0].getAnnotatedBounds();
        System.out.println(bounds[0] instanceof AnnotatedParameterizedType);
        AnnotatedParameterizedType callable = (AnnotatedParameterizedType) bounds[0];
        callable.getAnnotatedActualTypeArguments(); // throws exception
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None.

FREQUENCY : always



Comments
Changeset: 53a4ef26 Author: Rafael Winterhalter <winterhalter@openjdk.org> Committer: Joel Borggr��n-Franck <jfranck@openjdk.org> Date: 2020-09-17 07:26:49 +0000 URL: https://git.openjdk.java.net/jdk/commit/53a4ef26
17-09-2020

This issue is a duplicate of JDK-8202469: The reason for both problems is that the type path of a type annotation on a type variable is incorrectly resolved such that type annotations are always added to the first variable. See https://mail.openjdk.java.net/pipermail/core-libs-dev/2019-August/061654.html
09-09-2019

This issue is reproducible on 8, 9, 10, and 11 builds There is no issue observed on Eclipse. Below is the snapshot executed on 11 ea b11 -sh-4.2$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+11/bin/javac Foo.java -sh-4.2$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+11/bin/java Foo true Exception in thread "main" java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface Foo$SampleTypeAnnotation: @Foo$SampleTypeAnnotation() at java.base/sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.java:380) at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(AnnotatedTypeFactory.java:140) at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedWildcardTypeImpl.<init>(AnnotatedTypeFactory.java:326) at java.base/sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:82) at java.base/sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.getAnnotatedActualTypeArguments(AnnotatedTypeFactory.java:291) at Foo.main(Foo.java:22)
01-05-2018