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

Validator.validateValue() throws UnexpectedTypeException even when the passed value has a validator.

Description

I'm trying to validate individual UI text fields so that I can display user cues as the user is typing. When I call validateValue() on the string returned by the field I get the exception below. The test is below the exception. In the test I pass a string to validateValue() but it complains that there isn't a constraint validator for the JTextField where the validation annotation is attached. Since the text field isn't being referenced (it isn't even instantiated in the test case) it shouldn't matter where the validation was defined.

Exception from validateValue() call.

1 2 3 4 5 6 7 8 9 10 11 12 Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type: javax.swing.JTextField at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:383) at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:364) at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:313) at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:144) 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)

This is the test class:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import javax.swing.JTextField; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; import org.hibernate.validator.constraints.NotBlank; public class Test { public static void main(String[] args) { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); // Throws exception validator.validateValue(TestPanel.class, "testField", "testString", new Class[0]); } } class TestPanel { @NotBlank public JTextField testField = new JTextField(); }

Environment

My test was run on Java 1.6.0_27 in Eclipse.

Status

Assignee

Unassigned

Reporter

Jay Gorrell

Labels

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Affects versions

4.2.0.Final

Priority

Major