[hibernate-issues] [Hibernate-JIRA] Commented: (HV-196) validateValue incorrectly reports java.lang.IllegalArgumentException on non constrained properties
Ed Burns (JIRA)
noreply at atlassian.com
Mon Oct 12 15:44:41 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HV-196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34156#action_34156 ]
Ed Burns commented on HV-196:
-----------------------------
Yes, I tested the same glassfish v3 build with a bean-validator.jar OSGi module based on your Beta3, with the same test app, and found that it did work. IT does appear to be a regression.
> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list