Uploaded image for project: 'Hibernate Validator'
  1. HV-931

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.1.2.Final
    • Fix Version/s: 5.1.3.Final, 5.2.0.Alpha1
    • Component/s: engine
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true
    • Sprint:

      Description

      I have the following validation rules defined in an interface:

      @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:

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sosna Xavier Sosnovsky
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: