[
http://opensource.atlassian.com/projects/hibernate/browse/HV-196?page=com...
]
Hardy Ferentschik commented on HV-196:
--------------------------------------
Hi Ed, are you sure you are not getting a IllegalArgumentException due to an invalid
constraint declaration. We made a change so that if for example in the Size constraint min
> max a IllegalArgumentException is thrown instead of a ConstraintDeclarationException.
See HV-134
validateValue for unconstraint properties should still be ignored. There is even a test
for that in the TCK - ValidateValueTest.testExistingPropertyWoConstraintsNorCascaded().
See
http://fisheye.jboss.org/browse/Hibernate/beanvalidation/tck/trunk/src/ma...
In case you still think there is an issue it is probably better you open a new issue.
Maybe you could provide a test case?
validateValue incorrectly reports java.lang.IllegalArgumentException
on non constrained properties
--------------------------------------------------------------------------------------------------
Key: HV-196
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-196
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.0.0.Beta2
Environment: HEAD of JSR-303 RI
Reporter: Ed Burns
Fix For: 4.0.0.Beta3
Attachments: simple-bv-servlet.war
Calling validator.validateValue() seems to fail when it shouldn't.
Consider this pojo:
8<----------------------------------
package simple_bv_servlet;
import java.util.List;
import javax.validation.constraints.NotNull;
public class Person {
@NotNull
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@NotNull
private String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
private List<String> listOfString;
public List<String> getListOfString() {
return listOfString;
}
public void setListOfString(List<String> listOfString) {
this.listOfString = listOfString;
}
}
8<----------------------------
And consider this selvlet which validates this pojo in its doGet() impl.
8<--------------------------------------
package simple_bv_servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidatorContext;
import javax.validation.ValidatorFactory;
public class SimpleBVServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
PrintWriter out = resp.getWriter();
resp.setContentType("text/html");
out.print("<html><head><title>SimpleBVServlet</title></head><body>");
ValidatorFactory validatorFactory = null;
validatorFactory = Validation.buildDefaultValidatorFactory();
out.print("<p>");
out.print("Obtained ValidatorFactory: " + validatorFactory +
".");
out.print("</p>");
ValidatorContext validatorContext = validatorFactory.usingContext();
javax.validation.Validator beanValidator = validatorContext.getValidator();
out.print("<h1>");
out.print("Validating invalid person class using validateValue.");
out.print("</h1>");
List<String> value = new ArrayList<String>();
value.add("one");
value.add("two");
value.add("three");
Set<ConstraintViolation<Person>> violations =
beanValidator.validateValue(Person.class, "listOfString",
value);
if (violations.isEmpty()) {
out.print("<p>");
out.print("No ConstraintViolations found.");
out.print("</p>");
} else {
for (ConstraintViolation<Person> curViolation : violations) {
out.print("<p>");
out.print("ConstraintViolation: message: " +
curViolation.getMessage() +
" propertyPath: " + curViolation.getPropertyPath());
out.print("</p>");
}
}
Person person = new Person();
out.print("<h1>");
out.print("Validating invalid person instance using validate.");
out.print("</h1>");
violations = beanValidator.validate(person);
if (violations.isEmpty()) {
out.print("<p>");
out.print("No ConstraintViolations found.");
out.print("</p>");
} else {
for (ConstraintViolation<Person> curViolation : violations) {
out.print("<p>");
out.print("ConstraintViolation: message: " +
curViolation.getMessage() +
" propertyPath: " + curViolation.getPropertyPath());
out.print("</p>");
}
}
out.print("<h1>");
out.print("Validating valid person.");
out.print("</h1>");
person.setFirstName("John");
person.setLastName("Yaya");
violations = beanValidator.validate(person);
if (violations.isEmpty()) {
out.print("<p>");
out.print("No ConstraintViolations found.");
out.print("</p>");
} else {
for (ConstraintViolation<Person> curViolation : violations) {
out.print("<p>");
out.print("ConstraintViolation: message: " +
curViolation.getMessage() +
" propertyPath: " + curViolation.getPropertyPath());
out.print("</p>");
}
}
out.print("</body></html>");
}
}
8<------------------------
The call to
Set<ConstraintViolation<Person>> violations =
beanValidator.validateValue(Person.class, "listOfString",
value);
causes this exception to be thrown:
java.lang.IllegalArgumentException: Invalid property path. There is no property
listOfString in entity simple_bv_servlet.Person
But I say, doch, there is such a property on the Person.
This is new behavior in 4.0.0.Beta2, and it's breaking Glassfish.
Thanks,
Ed
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira