-
Bug
-
Resolution: Done
-
Major
-
None
-
Release Notes
-
-
-
-
-
-
-
Documented as Known Issue
This looks like a bug in IBM JDK. When introspecting a generic parameter of a method using getAnnotatedParameterTypes, IBM JDK returns an instance of sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl instead of the correct sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl
When introspecting generic fields or methods' return values this way, it works correctly!
The impact is that Hibernate Validator won't see nor be able to enforce constraints which are declared using type-use annotations on method parameters.
This also causes 8 failures in Hibernate Validator test suite when running with IBM JDK 8 - 4 in OptionalTypeAnnotationConstraintOnMethodTest and 4 in OptionalTypeAnnotationConstraintOnConstructorTest
Reproducer - simply compile this and run it using IBM JDK - it will fail with a ClassCastException, while it will finish successfully on other JDKs:
public class TypeUse_Parameter_Reproducer { public static void main(String[] args) throws NoSuchMethodException { final Method method = TypeUse_Parameter_Reproducer.class.getMethod("method", List.class); final AnnotatedType type = method.getAnnotatedParameterTypes()[0]; final AnnotatedParameterizedType annotatedParameterizedType = (AnnotatedParameterizedType)type; // booom! System.out .println(annotatedParameterizedType.getAnnotatedActualTypeArguments()[0].getAnnotations()[0]); // the expected output is: // @TypeUse_Parameter_Reproducer$TypeUseAnnotation(message=hi) } public void method(List<@TypeUseAnnotation(message = "hi") String> param) { } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE_USE}) public @interface TypeUseAnnotation { String message() default "blabla"; } }
Btw. To be able to run the Hibernate Validator test suite using IBM JDK, you also need to get rid of classes which depend on JavaFX and turn off the maven-enforcer-plugin using -Denforcer.skip=true..
- cloned from
-
HV-1024 Loading...