0 Replies Latest reply on Nov 6, 2012 5:43 AM by Nicklas Karlsson

    Strange JSR-303 validation path

    Nicklas Karlsson Master

      This is not strictly an AS7 question but since I know you are all bored and looking for an easy challenge for a change ;-)

       

      I have a

       

       

      public class Master
      {
         @Valid
         private List<Detail> details;
      
         public Master()
         {
            details = new ArrayList<Detail>();
            details.add(new Detail());
            details.add(new Detail());
         }
      
         public List<Detail> getDetails()
         {
            return details;
         }
      
         public void setDetails(List<Detail> details)
         {
            this.details = details;
         }
       
      }
      
      

       

      and a

       

       

      @DetailValue
      public class Detail
      {
      }
      
      

       

      with a

       

       

      @Documented
      @Constraint(validatedBy = DetailValueValidator.class)
      @Target(TYPE)
      @Retention(RUNTIME)
      public @interface DetailValue
      {
         String message() default "{nada}";
       
         Class<?>[] groups() default {};
       
         Class<? extends Payload>[] payload() default {};
      }
      
      and
      
      public class DetailValueValidator implements ConstraintValidator<DetailValue, Detail>
      {
       
         public void initialize(DetailValue constraintAnnotation)
         {
         }
       
         public boolean isValid(Detail value, ConstraintValidatorContext context)
         {
            return false;
         }
      }
      
      
      

       

      and test it with a

       

       

         public static void main(String[] args)
         {
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            Master master = new Master();
            for (ConstraintViolation<Master> constraintViolation : validator.validate(master))
            {
               System.out.println(constraintViolation.getPropertyPath());
            }
         }
      
      

       

      How come I see

       

       

      details[1]
      details[1]
      
      when I trough the debugger in the DetailValueValidator ConstraintValidatorContext see the correct paths details[0] and details[1] being processed?