PhilC (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiZmU3NDdhY2RiM...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1760?atlOrigin=eyJpIjoiZmU3NDdh...
) HV-1760 (
https://hibernate.atlassian.net/browse/HV-1760?atlOrigin=eyJpIjoiZmU3NDdh...
) @Negative*/@Positive* do not support CharSequence as documented (
https://hibernate.atlassian.net/browse/HV-1760?atlOrigin=eyJpIjoiZmU3NDdh...
)
Issue Type: Bug Affects Versions: 6.1.2.Final Assignee: Unassigned Components: validators
Created: 09/Mar/2020 12:58 PM Priority: Minor Reporter: PhilC (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
The hibernate validator documentation (
https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_si...
) for @Negative , @NegativeOrZero , @Positive , and @PositiveOrZero states that hibernate
validator supports validating any subtype of CharSequence :
additionally supported by HV: any sub-type of CharSequence (the numeric
value represented by the character sequence is evaluated)
However, when attempting to validate a String field with any of those constraints,
hibernate validator throws the following exception:
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for
constraint 'javax.validation.constraints.Negative' validating type 'java.lang.
String '. Check configuration for 'string'
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getExceptionForNullValidator(ConstraintTree.java:116)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getInitializedConstraintValidator(ConstraintTree.java:162)
at
org.hibernate.validator.internal.engine.constraintvalidation.SimpleConstraintTree.validateConstraints(SimpleConstraintTree.java:54)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:75)
at
org.hibernate.validator.internal.metadata.core.MetaConstraint.doValidateConstraint(MetaConstraint.java:130)
at
org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:123)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:555)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForSingleDefaultGroupElement(ValidatorImpl.java:518)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:488)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:450)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:400)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:172)
at NegativeConstraintTest.test(NegativeConstraintTest.java:25)
Here is a unit test that demonstrates the problem:
import org.junit.jupiter.api.Test;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.Negative;
public class NegativeConstraintTest {
public static class Target {
private final String string;
public Target( String string) {
this.string = string;
}
@Negative
public String getString() {
return string;
}
}
@Test
public void test() {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
validator.validate( new Target( "1.0" ));
}
}
Please either update the documentation, or add support for CharSequences to these
constraints.
(
https://hibernate.atlassian.net/browse/HV-1760#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1760#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:db27712 )