-
Type:
Bug
-
Status: Resolved
-
Priority:
P4
-
Resolution: Not an Issue
-
Affects Version/s: 8, 9
-
Fix Version/s: None
-
Component/s: core-libs
-
Subcomponent:
-
CPU:x86_64
-
OS:windows_7
FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If the return type of a method is an array it's not possible to get its type annotations with the method java.lang.reflect.Method.getAnnotatedReturnType()
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code attached below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
sayHello:@AnnotationTest$MyAnnotation(value=sayHello)
sayHello1:@AnnotationTest$MyAnnotation(value=sayHello1)
sayHello2:@AnnotationTest$MyAnnotation(value=sayHello2)
ACTUAL -
sayHello:@AnnotationTest$MyAnnotation(value=sayHello)
sayHello1:@AnnotationTest$MyAnnotation(value=sayHello1)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Method;
import java.util.List;
public class AnnotationTest {
@Target({ ElementType.TYPE_PARAMETER, ElementType.TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String value();
}
public interface ToImplement {
public @MyAnnotation("sayHello") String sayHello();
public @MyAnnotation("sayHello1") List<String> sayHello1();
public @MyAnnotation("sayHello2") String[] sayHello2();
}
public static void main(String[] args) throws Exception {
for (Method m : ToImplement.class.getMethods()) {
AnnotatedType returnType = m.getAnnotatedReturnType();
for (Annotation a : returnType.getAnnotations()) {
System.out.println(m.getName() + ":" + a);
}
}
}
}
---------- END SOURCE ----------
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
If the return type of a method is an array it's not possible to get its type annotations with the method java.lang.reflect.Method.getAnnotatedReturnType()
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code attached below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
sayHello:@AnnotationTest$MyAnnotation(value=sayHello)
sayHello1:@AnnotationTest$MyAnnotation(value=sayHello1)
sayHello2:@AnnotationTest$MyAnnotation(value=sayHello2)
ACTUAL -
sayHello:@AnnotationTest$MyAnnotation(value=sayHello)
sayHello1:@AnnotationTest$MyAnnotation(value=sayHello1)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Method;
import java.util.List;
public class AnnotationTest {
@Target({ ElementType.TYPE_PARAMETER, ElementType.TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String value();
}
public interface ToImplement {
public @MyAnnotation("sayHello") String sayHello();
public @MyAnnotation("sayHello1") List<String> sayHello1();
public @MyAnnotation("sayHello2") String[] sayHello2();
}
public static void main(String[] args) throws Exception {
for (Method m : ToImplement.class.getMethods()) {
AnnotatedType returnType = m.getAnnotatedReturnType();
for (Annotation a : returnType.getAnnotations()) {
System.out.println(m.getName() + ":" + a);
}
}
}
}
---------- END SOURCE ----------