Uploaded image for project: 'Hibernate Validator'
  1. HV-864

Cross-parameter constraint is disallowed by Annotation Processor

    Details

      Description

      I am using hibernate validator 5.0.3 with Java 1.6.0_45-b06-451 on OSX 10.9.1.

      I have created a cross-parameter constraint as follows:

      CrossParameterConstraint.java
      
      @Target({ANNOTATION_TYPE, METHOD, CONSTRUCTOR})
      @Retention(RUNTIME)
      @Constraint(validatedBy = {CrossParameterConstraintValidator.class})
      @Documented
      public @interface CrossParameterConstraint {
      
          String message() default "{CrossParameterConstraint.message}";
      
          Class<?>[] groups() default {};
      
          Class<? extends Payload>[] payload() default {};
      
      }
      
      CrossParameterConstraintValidator.java
      @SupportedValidationTarget(ValidationTarget.PARAMETERS)
      public class CrossParameterConstraintValidator implements
              CrossParameterConstraintValidator<CrossParameterConstraint, Object[]> {
      
          @Override
          public void initialize(final CrossParameterConstraint constraintAnnotation) {
          }
      
          @Override
          public boolean isValid(final Object[] value, final ConstraintValidatorContext context) {
              // some validation logic
              return true;
          }
      
      }
      

      The above constraint is used in a method as follows:

      CrossParameterConstraintUsageExample.java
      public class CrossParameterConstraintUsageExample {
          @CrossParameterConstraint
          public String test(Integer parameter, String anotherParameter) {
              return parameter + anotherParameter;
          }
      }
      

      I have configured the Annotation Processor in pom.xml
      as follows:

      pom.xml
              <dependency>
                  <groupId>org.hibernate</groupId>
                  <artifactId>hibernate-validator-annotation-processor</artifactId>
                  <version>5.0.3.Final</version>
              </dependency>
      

      When trying to compile, the Annotation Processor reports the following error:

      The annotation @CrossParameterConstraint is disallowed for the return type of this method.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: