JDK-8146854 : Issues with Type annotations on parameters of multiple type variable bound types
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8u66,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2016-01-12
  • Updated: 2018-10-31
  • Resolved: 2018-10-31
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.
Other
tbd_minorResolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
If the parameter of a type variable bound type is annotated and another bound of the same type variable defines the same type annotation on a parameter of the second bound with the same index, both type variables appear on both bounds and an exception is thrown.

The code example demonstrates this problem.

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

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An exception is thrown.
ACTUAL -
No exception is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface net.bytebuddy.test.Sample: @net.bytebuddy.test.Sample()
	at sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.java:360)
	at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(AnnotatedTypeFactory.java:139)
	at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedWildcardTypeImpl.<init>(AnnotatedTypeFactory.java:274)
	at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:82)
	at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.getAnnotatedActualTypeArguments(AnnotatedTypeFactory.java:255)
	at net.bytebuddy.test.Foo.main(Foo.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedParameterizedType;
import java.util.List;
import java.util.concurrent.Callable;

public class Foo<T extends List<@Sample ?> & Callable<@Sample ?>> {

    public static void main(String[] args) {
        ((AnnotatedParameterizedType) Foo.class.getTypeParameters()[0].getAnnotatedBounds()[0]).getAnnotatedActualTypeArguments();
    }
}

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

}
---------- END SOURCE ----------


Comments
Attached test case reproduced on: JDK 8u66 - Fail JDK 8u72 - Fail JDK 9ea - Fail Following is the output on all versions: Exception in thread "main" java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface Sample: @Sample() at sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.java:361) at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(AnnotatedTypeFactory.java:139) at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedWildcardTypeImpl.<init>(AnnotatedTypeFactory.java:274) at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:82) at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.getAnnotatedActualTypeArguments(AnnotatedTypeFactory.java:255) at JI9028520.main(JI9028520.java:12)
12-01-2016