bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "viktor (JIRA)" <j...@apache.org>
Subject [jira] [Created] (BVAL-125) "No validator could be found for type ..." for overloaded methods with more specific return type
Date Fri, 21 Mar 2014 13:57:43 GMT
viktor created BVAL-125:
---------------------------

             Summary: "No validator could be found for type ..." for overloaded methods with
more specific return type
                 Key: BVAL-125
                 URL: https://issues.apache.org/jira/browse/BVAL-125
             Project: BVal
          Issue Type: Bug
    Affects Versions: 0.5
         Environment: Java(TM) SE Runtime Environment (build 1.8.0-b132)
Linux 3.11.10-7-desktop x86_64
            Reporter: viktor


Example:

import java.lang.reflect.Method;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;

public class App {
  public static interface Identifiable {
    Object getId();
  }
  public static class Test implements Identifiable {
    @javax.validation.constraints.Pattern(regexp = "\\w+")
    public String getId() {
      return "ok";
    }
  }
  public static void main(String[] args) {
    ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
    Test test = new Test();
    System.out.println("methods: ");
    for(Method m: test.getClass().getMethods()) {
      System.out.println("  " + m);
    }
    Set<ConstraintViolation<Test>> set = vf.getValidator().validate(test);
    System.out.println("set:" + set);
  }
}

Print to ouput stream: 

methods: 
  public java.lang.String ru.kih.test.App$Test.getId()
  public java.lang.Object ru.kih.test.App$Test.getId()
  ... other methods was skipped ...
Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be
found for type java.lang.Object. See: @Pattern at public java.lang.Object ru.kih.test.App$Test.getId()
	at org.apache.bval.jsr303.AnnotationProcessor.checkOneType(AnnotationProcessor.java:326)
	at org.apache.bval.jsr303.AnnotationProcessor.getConstraintValidator(AnnotationProcessor.java:301)
	at org.apache.bval.jsr303.AnnotationProcessor.applyConstraint(AnnotationProcessor.java:241)
	at org.apache.bval.jsr303.AnnotationProcessor.processAnnotation(AnnotationProcessor.java:149)
	at org.apache.bval.jsr303.AnnotationProcessor.processAnnotations(AnnotationProcessor.java:90)
	at org.apache.bval.jsr303.Jsr303MetaBeanFactory.processClass(Jsr303MetaBeanFactory.java:156)
	at org.apache.bval.jsr303.Jsr303MetaBeanFactory.buildMetaBean(Jsr303MetaBeanFactory.java:95)
	at org.apache.bval.MetaBeanBuilder.buildForClass(MetaBeanBuilder.java:131)
	at org.apache.bval.MetaBeanManager.findForClass(MetaBeanManager.java:102)
	at org.apache.bval.jsr303.ClassValidator.validate(ClassValidator.java:140)
	at ru.kih.test.App.main(App.java:34)




--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message