We're updating the issue view to help you get more done. 

NPE when validating an object tree whith a class whose parent has defined property constraints

Description

Today I switched from HV 5.0.1 to 5.2.1 and happily enough to know that it was claimed to be a drop-in replacement for all 5.x versions, I started my code and WOW! My code throws NPE at our initial system validations with this stack trace:

1 2 3 4 5 6 7 8 9 10 java.lang.NullPointerException at org.hibernate.validator.internal.engine.ValueContext.appendNode(ValueContext.java:131) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:539) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:490) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:454) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:406) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:770) at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:656) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:415) at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:204)

Working a little bit on the issue, I could manage to reproduce it in a simple unit test that I've attached. I repeat it here for the sake of description.

Suppose that we have these simple classes:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 public class MainBean { @Valid public TopBean child; } public class TopBean { @NotNull private String getProperty() { return null; } } public class BottomBean extends TopBean { }

If I want to validate an instance of MainBean which has an instance of BottomBean as its child, the mentioned exception occurs!

I searched the issue database to find that has already reported this same issue, but since there has been no test cases, the issue was resolved with "Cannot Reproduce". As I could not reopen the issue, I decided to report it here since I think it is a downside to a very reliable library.

Environment

Java: 8u60 HV: 5.2.1.Final TestNG 6.9.5

Status

Assignee

Gunnar Morling

Reporter

Hamid Nazari

Suitable for new contributors

Yes, likely

Components

Fix versions

Affects versions

5.2.1.Final

Priority

Major