Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-1605

Hibernate Validator can't introspect AnnotatedParameterizedTypes from method parameters using IBM JDK

    XMLWordPrintable

Details

    • Release Notes
    • Hide
      An issue was identified in the IBM JVM implementation which makes it impossible to introspect annotated parametrized types from method parameters using reflection when running on an IBM JVM. This affects Hibernate Validator, the Bean Validation implementation in JBoss EAP, in a way that custom validation constraints based on type-use annotations on method parameters will not work. Example:

      public void addSomeInterestingStrings(List<@Interesting String> strings)

      Assuming that @Interesting is declared as a validation constraint, this validation constraint will not be applied correctly when validating the "strings" argument. This is an issue in the JVM implementation, was reported to IBM and will be fixed in a future release of IBM Java. This doesn't affect other JVM implementations.
      Show
      An issue was identified in the IBM JVM implementation which makes it impossible to introspect annotated parametrized types from method parameters using reflection when running on an IBM JVM. This affects Hibernate Validator, the Bean Validation implementation in JBoss EAP, in a way that custom validation constraints based on type-use annotations on method parameters will not work. Example: public void addSomeInterestingStrings(List<@Interesting String> strings) Assuming that @Interesting is declared as a validation constraint, this validation constraint will not be applied correctly when validating the "strings" argument. This is an issue in the JVM implementation, was reported to IBM and will be fixed in a future release of IBM Java. This doesn't affect other JVM implementations.
    • Documented as Known Issue

    Description

      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..

      Attachments

        Issue Links

          Activity

            People

              jmartisk@redhat.com Jan Martiska
              jmartisk@redhat.com Jan Martiska
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: