Templated interface method parameter constraints are ignored in EAP 6
Issue
- Define/implement a generic interface with a
NotNullvalidated method parameter
import javax.validation.constraints.NotNull;
public static interface IAnimal<T> {
public void setDetail(@NotNull T detail);
}
public static class Cat implements IAnimal<String> {
public void setDetail(String detail) {
...
}
}
- Validation fails to enforce the constraint declared in the interface
import javax.validation.Validation;
import org.hibernate.validator.method.MethodValidator;
import org.hibernate.validator.method.MethodConstraintViolation;
import junit.framework.TestCase;
public class TestHibernate extends TestCase {
public void testValidation() throws Throwable {
Cat cat = new Cat();
MethodValidator methodValidator = Validation.buildDefaultValidatorFactory().getValidator().unwrap(MethodValidator.class);
Set<MethodConstraintViolation<Cat>> violations = methodValidator.validateAllParameters(
cat, getSetDetailStringMethod(cat.getClass()), new Object[] { null }
);
assertEquals("One violation expected", 1, violations.size()); // this fails
}
}
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate Validator 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.