@Min and @DecimalMin fail on BigDecimal.valueOf(Double.MIN_VALUE)

Description

Please see below test. Current System is based on Spring-Boot 2.2.6.RELEASE which brings Hibernate-Validator 6.0.18 bundled.

```
import static org.assertj.core.api.Assertions.assertThat;

import java.math.BigDecimal;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class HibernateValidatorTest {
Validator validator;

@BeforeEach
public void setup() {
validator = Validation.buildDefaultValidatorFactory().getValidator();
}

public static class TestClass {
BigDecimal decimalMinValue;
BigDecimal minValue;

@DecimalMin("-1000.0")
public BigDecimal getDecimalMinValue() {
return decimalMinValue;
}

@Min(-1000)
public BigDecimal getMinValue() {
return minValue;
}
}

@Test
public void shouldWork() {
var testClass = new TestClass();
testClass.decimalMinValue = BigDecimal.ZERO;
testClass.minValue = BigDecimal.ZERO;

var violations = validator.validate(testClass);
assertThat(violations).isEmpty();
}

@Test
public void shouldWork_Minus1001() {
var testClass = new TestClass();
testClass.decimalMinValue = new BigDecimal("-1001");
testClass.minValue = new BigDecimal("-1001");

var violations = validator.validate(testClass);
assertThat(violations).hasSize(2);
}

@Test
public void shouldWork_DoubleMinValue() {
var testClass = new TestClass();
testClass.decimalMinValue = BigDecimal.valueOf(Double.MIN_VALUE);
testClass.minValue = BigDecimal.valueOf(Double.MIN_VALUE);

var violations = validator.validate(testClass);
assertThat(violations).hasSize(2); // no validation errors, has size 0!
}
}

```



Environment

None

Activity

Show:
Yoann Rodière
September 1, 2020, 8:27 AM
Edited

Double.MIN_VALUE is not the lowest negative value that can be represented as a double, it's the lowest positive value that can be represented as a double. It's equal to 4.9e-324, which is higher than zero and higher than -1000. I think everything works as expected.

You probably meant to test -Double.MAX_VALUE.

Dominik Dorn
September 1, 2020, 3:52 PM

doh… thanks a lot!

Yoann Rodière
September 7, 2020, 7:42 AM

Thanks for confirming it was a misunderstanding. Closing!

Assignee

Yoann Rodière

Reporter

Dominik Dorn

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Priority

Major
Configure