1 Reply Latest reply on Sep 24, 2015 4:50 AM by Martin Kouba

    @WithAnnotations does not check interfaces for ProcessAnnotatedType

    Davide D'Alto Newbie

      In Hibernate Validator we have created an extension to validate

      the parameter of a method called.

       

      The extension looks like this:

       

      public class ValidationExtension implements Extension {

       

        ...

       

        public <T> void processAnnotatedType(@Observes @WithAnnotations({ Constraint.class, Valid.class, ValidateOnExecution.class }) ProcessAnnotatedType<T> processAnnotatedTypeEvent) {

          ...

        }

      }

       

      You can see the whole file on GitHub: https://github.com/hibernate/hibernate-validator/blob/master/cdi/src/main/java/org/hibernate/validator/internal/cdi/ValidationExtension.java#L219

       

      Our current use case is the deployment of a WAR with a JSF ManagedBean that calls a StatelessBean, this are the classes in short:

       

      Managed Bean:

       

      @javax.faces.bean.ManagedBean(name = "greeter", eager = true)

      public class Greeter {

        @Inject

        private StatelessBeanInterface bean;

       

        public String getMessage() {

          return bean.lookup( null );

        }

      }

       

      Stateless bean interface:

       

      public interface StatelessBeanInterface {

        String lookup(@NotNull String text);

      }

       

      Stateless bean implementation:

       

      @Stateless

      public class StatelessBean implements StatelessBeanInterface {

        @Override

        public String lookup(String text) {

          ...

        }

      }

       

      This commit add a test case to hibernate validator and show all the classes: https://github.com/DavideD/hibernate-validator/commit/9e86edcb87c6b1698ce64620680a1171cb713bff

       

      The problem we are having is that the stateless bean is not validated because ValidationExtension#processAnnotatedType does not get called as expected.

       

      Everything works fine if I apply one of the following changes:

      - add @NotNull to the signature of the implementation and not the interface;

      - remove the @WithAnnotations

       

      It seems the problem is that the annotation is defined on the interface instead of the class implementing it.

      Is this expected? Am I doing something wrong?

       

      Thanks,

      Davide