This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git

commit cd8bbdd0ef3181926c507d0afe046a59ca582ebf
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jun 19 21:21:13 2026 +0000

    Compare Exact value in BigDecimalValidator min/max range checks (#401).
    
    - Internal refactoring
---
 src/changes/changes.xml                             |  3 ++-
 .../validator/routines/BigDecimalValidator.java     | 21 +++++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ae525924..2813145e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,7 +83,8 @@ The <action> type attribute can be add,update,fix,remove.
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary 
Gregory">Compare CAS and EC check digit against validated code, not raw input 
(#398).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq">Prevent URL path 
traversal bypass via percent encoding in UrlValidator (#383).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq">Fix ISIN 
country-code check using untrimmed input (#399).</action>
-    <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Use 
compareTo() in BigIntegerValidator.minValue() (#400)..</action>
+    <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Use 
compareTo() in BigIntegerValidator.minValue() (#400).</action>
+    <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary 
Gregory">Compare Exact value in BigDecimalValidator min/max range checks 
(#401).</action>
     <!-- ADD -->
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use 
CheckDigitException.CheckDigitException(String, Object...) (#389).</action>
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use 
ValidatorException.ValidatorException(Throwable). Call sites that previously 
called new ValidatorException(Throwable#getMessage()) now preserve that 
exception (#390).</action>
diff --git 
a/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java 
b/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java
index 101be583..377144bd 100644
--- 
a/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java
+++ 
b/src/main/java/org/apache/commons/validator/routines/BigDecimalValidator.java
@@ -71,6 +71,17 @@ public class BigDecimalValidator extends 
AbstractNumberValidator {
 
     private static final BigDecimalValidator VALIDATOR = new 
BigDecimalValidator();
 
+    /**
+     * Compares the given {@code BigDecimal} with the given double value.
+     *
+     * @param bigDecimal The {@code BigDecimal} to compare.
+     * @param value      The double value to compare with.
+     * @return a negative integer, zero, or a positive integer as this {@code 
BigDecimal} is less than, equal to, or greater than the specified double value.
+     */
+    private static int compareTo(final BigDecimal bigDecimal, final double 
value) {
+        return bigDecimal.compareTo(BigDecimal.valueOf(value));
+    }
+
     /**
      * Gets the singleton instance of this validator.
      *
@@ -147,10 +158,7 @@ public class BigDecimalValidator extends 
AbstractNumberValidator {
      *         or equal to the maximum.
      */
     public boolean maxValue(final BigDecimal value, final double max) {
-        if (Double.isFinite(max)) {
-            return value.compareTo(BigDecimal.valueOf(max)) <= 0;
-        }
-        return value.doubleValue() <= max;
+        return Double.isFinite(max) ? compareTo(value, max) <= 0 : 
value.doubleValue() <= max;
     }
 
     /**
@@ -162,10 +170,7 @@ public class BigDecimalValidator extends 
AbstractNumberValidator {
      *         or equal to the minimum.
      */
     public boolean minValue(final BigDecimal value, final double min) {
-        if (Double.isFinite(min)) {
-            return value.compareTo(BigDecimal.valueOf(min)) >= 0;
-        }
-        return value.doubleValue() >= min;
+        return Double.isFinite(min) ? compareTo(value, min) >= 0 : 
value.doubleValue() >= min;
     }
 
     /**

Reply via email to