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

Using NaN and Infinity triggers an exception for (Decimal)Min and (Decimal)Max constraints

Description

I have the following validation rules defined in an interface:

1 2 3 4 @NotNull @DecimalMax(value= "90.0") @DecimalMin(value= "-90.0") Double getLatitude();

In my tests, I also pass unexpected values such as Double.NAN or Double.POSITIVE_INFINITY.

This triggers an exception:

1 2 3 4 5 6 7 8 9 10 javax.validation.ValidationException: HV000028: Unexpected exception during isValid call. at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:286) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:133) at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91) at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:83) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:547) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:487) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:451) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:403) at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206)

The exception is caused by the call to BigDecimal.valueOf(double val) in org.hibernate.validator.internal.constraintvalidators.bv.DecimalMaxValidatorForNumber, which throws an exception if val is infinite or NaN.

The issue can be reproduced using the attached project.

Environment

None

Status

Assignee

Unassigned

Reporter

Xavier Sosnovsky

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

5.1.2.Final

Priority

Minor