I've don a little further testing and it seems that you call the validator for the bean regardless of what the passed type is. Maybe the documentation for validateValue() needs to reflect that the value that is passed must be of the same type as the field where the annotation is defined. I don't have another test case for this, but assume that I wrote a NotNullJTextFieldValidator class, and configured everything to pick up the new validator for @NotNull annotation definitions. Running the test case would then throw an exception similar to this:
{noframe}javax.validation.ValidationException: Unexpected exception during isValid call
at org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:281)
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:153)
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117)
at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84)
at org.hibernate.validator.engine.ValidatorImpl.validatePropertyForDefaultGroup(ValidatorImpl.java:829)
at org.hibernate.validator.engine.ValidatorImpl.validatePropertyForCurrentGroup(ValidatorImpl.java:742)
at org.hibernate.validator.engine.ValidatorImpl.validateValueInContext(ValidatorImpl.java:699)
at org.hibernate.validator.engine.ValidatorImpl.validateValue(ValidatorImpl.java:176)
at com.tpt.common.Test.main(Test.java:21)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.JTextField
at com.tpt.ui.common.validators.NotNullJTextFieldValidator.isValid
at org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:278)
... 37 more{noframe}
I've don a little further testing and it seems that you call the validator for the bean regardless of what the passed type is. Maybe the documentation for validateValue() needs to reflect that the value that is passed must be of the same type as the field where the annotation is defined. I don't have another test case for this, but assume that I wrote a NotNullJTextFieldValidator class, and configured everything to pick up the new validator for @NotNull annotation definitions. Running the test case would then throw an exception similar to this:
{noframe}javax.validation.ValidationException: Unexpected exception during isValid callat org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:281)
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:153)
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117)
at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84)
at org.hibernate.validator.engine.ValidatorImpl.validatePropertyForDefaultGroup(ValidatorImpl.java:829)
at org.hibernate.validator.engine.ValidatorImpl.validatePropertyForCurrentGroup(ValidatorImpl.java:742)
at org.hibernate.validator.engine.ValidatorImpl.validateValueInContext(ValidatorImpl.java:699)
at org.hibernate.validator.engine.ValidatorImpl.validateValue(ValidatorImpl.java:176)
at com.tpt.common.Test.main(Test.java:21)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.JTextField
at com.tpt.ui.common.validators.NotNullJTextFieldValidator.isValid
at org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:278)
... 37 more{noframe}