You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/07/04 18:53:46 UTC

(commons-validator) branch master updated (339b5250 -> e095d696)

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

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


    from 339b5250 Merge pull request #416 from sahvx655-wq/integer-range-exact-bound
     new 1d544ac6 Sort members
     new e095d696 Compare exact bound in AbstractNumberValidator range checks (#416).

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  1 +
 .../validator/routines/ByteValidatorTest.java      | 30 +++++++--------
 .../validator/routines/CurrencyValidatorTest.java  | 32 ++++++++--------
 .../validator/routines/FloatValidatorTest.java     | 32 ++++++++--------
 .../validator/routines/LongValidatorTest.java      | 44 +++++++++++-----------
 .../validator/routines/PercentValidatorTest.java   | 32 ++++++++--------
 .../validator/routines/ShortValidatorTest.java     | 30 +++++++--------
 7 files changed, 101 insertions(+), 100 deletions(-)


(commons-validator) 01/02: Sort members

Posted by gg...@apache.org.
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 1d544ac65a1c617e9fc8382f0958b04d68ed48e7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jul 4 14:52:48 2026 -0400

    Sort members
---
 .../validator/routines/ByteValidatorTest.java      | 30 +++++++--------
 .../validator/routines/CurrencyValidatorTest.java  | 32 ++++++++--------
 .../validator/routines/FloatValidatorTest.java     | 32 ++++++++--------
 .../validator/routines/LongValidatorTest.java      | 44 +++++++++++-----------
 .../validator/routines/PercentValidatorTest.java   | 32 ++++++++--------
 .../validator/routines/ShortValidatorTest.java     | 30 +++++++--------
 6 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java
index b08b231c..179b3051 100644
--- a/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/ByteValidatorTest.java
@@ -113,21 +113,6 @@ class ByteValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(validator.maxValue(number21, max), "maxValue() > max");
     }
 
-    /**
-     * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = ByteValidator.getInstance();
-        final Number value = Byte.valueOf((byte) 100);
-        // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false.
-        assertFalse(instance.minValue(Byte.valueOf((byte) 5), new BigDecimal("5.5")));
-    }
-
     /**
      * Test ByteValidator validate Methods
      */
@@ -161,4 +146,19 @@ class ByteValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(ByteValidator.getInstance().isValid(xxxx, pattern), "isValid(B) pattern");
         assertFalse(ByteValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both");
     }
+
+    /**
+     * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = ByteValidator.getInstance();
+        final Number value = Byte.valueOf((byte) 100);
+        // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false.
+        assertFalse(instance.minValue(Byte.valueOf((byte) 5), new BigDecimal("5.5")));
+    }
 }
diff --git a/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java
index 6191da6a..4f733b56 100644
--- a/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/CurrencyValidatorTest.java
@@ -47,22 +47,6 @@ class CurrencyValidatorTest {
         ukPound = new DecimalFormatSymbols(Locale.UK).getCurrencySymbol();
     }
 
-    /**
-     * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound,
-     * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = CurrencyValidator.getInstance();
-        final Number value = new BigDecimal("100");
-        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false.
-        assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5")));
-    }
-
     /**
      * Test Format Type
      */
@@ -147,6 +131,22 @@ class CurrencyValidatorTest {
         }
     }
 
+    /**
+     * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound,
+     * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = CurrencyValidator.getInstance();
+        final Number value = new BigDecimal("100");
+        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false.
+        assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5")));
+    }
+
     /**
      * Test currency values with a pattern
      */
diff --git a/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java
index f87f17fd..21c059c3 100644
--- a/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/FloatValidatorTest.java
@@ -138,22 +138,6 @@ class FloatValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(validator.maxValue(Float.NaN, 20), "maxValue() NaN");
     }
 
-    /**
-     * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound, so a {@code BigInteger} or
-     * {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = FloatValidator.getInstance();
-        final Number value = Float.valueOf(100);
-        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false.
-        assertFalse(instance.minValue(Float.valueOf(5), new BigDecimal("5.5")));
-    }
-
     /**
      * Test Float validation for values too small to handle. (slightly different from max/min which are the largest +ve/-ve
      */
@@ -211,6 +195,22 @@ class FloatValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(validator.isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both");
     }
 
+    /**
+     * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound, so a {@code BigInteger} or
+     * {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = FloatValidator.getInstance();
+        final Number value = Float.valueOf(100);
+        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false.
+        assertFalse(instance.minValue(Float.valueOf(5), new BigDecimal("5.5")));
+    }
+
     @Test
     void testSpecialSymbols() {
         final FloatValidator validator = FloatValidator.getInstance();
diff --git a/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java
index 0c36da94..48ec91f3 100644
--- a/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/LongValidatorTest.java
@@ -113,28 +113,6 @@ class LongValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(validator.maxValue(number21, 20), "maxValue() > max");
     }
 
-    /**
-     * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound rather than one narrowed to a
-     * {@code long}, so a {@code BigInteger}/{@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = LongValidator.getInstance();
-        final Number value = Long.valueOf(Long.MAX_VALUE);
-        // One above Long.MAX_VALUE narrows to Long.MIN_VALUE, wrongly reporting Long.MAX_VALUE as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false, 5 <= 5.5 is true.
-        assertFalse(instance.minValue(Long.valueOf(5), Double.valueOf(5.5)));
-        assertFalse(instance.minValue(Long.valueOf(5), new BigDecimal("5.5")));
-        assertTrue(instance.maxValue(Long.valueOf(5), new BigDecimal("5.5")));
-        // A non-finite bound falls back to the double comparison, matching the Big* validators.
-        assertFalse(instance.minValue(value, Double.NaN));
-        assertTrue(instance.maxValue(value, Double.POSITIVE_INFINITY));
-        assertTrue(instance.minValue(value, Double.NEGATIVE_INFINITY));
-    }
-
     /**
      * Test LongValidator validate Methods
      */
@@ -168,4 +146,26 @@ class LongValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(LongValidator.getInstance().isValid(xxxx, pattern), "isValid(B) pattern");
         assertFalse(LongValidator.getInstance().isValid(patternVal, pattern, Locale.GERMAN), "isValid(B) both");
     }
+
+    /**
+     * The {@link Number}-typed range overloads inherited from {@link AbstractNumberValidator} must compare the exact bound rather than one narrowed to a
+     * {@code long}, so a {@code BigInteger}/{@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = LongValidator.getInstance();
+        final Number value = Long.valueOf(Long.MAX_VALUE);
+        // One above Long.MAX_VALUE narrows to Long.MIN_VALUE, wrongly reporting Long.MAX_VALUE as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false, 5 <= 5.5 is true.
+        assertFalse(instance.minValue(Long.valueOf(5), Double.valueOf(5.5)));
+        assertFalse(instance.minValue(Long.valueOf(5), new BigDecimal("5.5")));
+        assertTrue(instance.maxValue(Long.valueOf(5), new BigDecimal("5.5")));
+        // A non-finite bound falls back to the double comparison, matching the Big* validators.
+        assertFalse(instance.minValue(value, Double.NaN));
+        assertTrue(instance.maxValue(value, Double.POSITIVE_INFINITY));
+        assertTrue(instance.minValue(value, Double.NEGATIVE_INFINITY));
+    }
 }
diff --git a/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java
index 9afe81b2..24f1fb99 100644
--- a/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/PercentValidatorTest.java
@@ -53,22 +53,6 @@ class PercentValidatorTest {
         validator = null;
     }
 
-    /**
-     * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound,
-     * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = PercentValidator.getInstance();
-        final Number value = new BigDecimal("100");
-        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false.
-        assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5")));
-    }
-
     /**
      * Test Format Type
      */
@@ -100,6 +84,22 @@ class PercentValidatorTest {
         assertFalse(validator.isValid("(12%)", Locale.US), "US wrong negative");
     }
 
+    /**
+     * The {@link Number}-typed range overloads inherited through {@link BigDecimalValidator} from {@link AbstractNumberValidator} must compare the exact bound,
+     * so a {@code BigInteger} or {@code BigDecimal} bound outside the long range or a fractional bound is not silently truncated.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = PercentValidator.getInstance();
+        final Number value = new BigDecimal("100");
+        // A bound above the long range must not narrow to a negative long and wrongly report 100 as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false.
+        assertFalse(instance.minValue(new BigDecimal("5"), new BigDecimal("5.5")));
+    }
+
     /**
      * Test Valid percentage values
      */
diff --git a/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java
index 66a86383..f3ceb74b 100644
--- a/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/ShortValidatorTest.java
@@ -71,6 +71,21 @@ class ShortValidatorTest extends AbstractNumberValidatorTest {
 
     }
 
+    /**
+     * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}.
+     */
+    @Test
+    void testNumberRangeExactBound() {
+        final AbstractNumberValidator instance = ShortValidator.getInstance();
+        final Number value = Short.valueOf((short) 100);
+        // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum.
+        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
+        assertTrue(instance.maxValue(value, aboveLongMax));
+        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
+        // A fractional bound is not floored: 5 >= 5.5 is false.
+        assertFalse(instance.minValue(Short.valueOf((short) 5), new BigDecimal("5.5")));
+    }
+
     /**
      * Test Short Range/Min/Max
      */
@@ -104,21 +119,6 @@ class ShortValidatorTest extends AbstractNumberValidatorTest {
         assertFalse(validator.maxValue(number21, max), "maxValue() > max");
     }
 
-    /**
-     * The inherited {@link Number}-typed range overloads must compare the exact bound rather than one narrowed to a {@code long}.
-     */
-    @Test
-    void testNumberRangeExactBound() {
-        final AbstractNumberValidator instance = ShortValidator.getInstance();
-        final Number value = Short.valueOf((short) 100);
-        // A bound above the long range narrows to a negative long, wrongly reporting 100 as above the maximum.
-        final Number aboveLongMax = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
-        assertTrue(instance.maxValue(value, aboveLongMax));
-        assertTrue(instance.isInRange(value, BigInteger.ZERO, aboveLongMax));
-        // A fractional bound is not floored: 5 >= 5.5 is false.
-        assertFalse(instance.minValue(Short.valueOf((short) 5), new BigDecimal("5.5")));
-    }
-
     /**
      * Test ShortValidator validate Methods
      */


(commons-validator) 02/02: Compare exact bound in AbstractNumberValidator range checks (#416).

Posted by gg...@apache.org.
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 e095d69655073309b33fabc382f8cbd1bef2fb83
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jul 4 14:53:40 2026 -0400

    Compare exact bound in AbstractNumberValidator range checks (#416).
---
 src/changes/changes.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 10db7393..24bac3eb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -98,6 +98,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Handle non-finite bounds in BigIntegerValidator range checks (#414).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Fix swapped constant maps in Form.process for extended forms (#413).</action>
     <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Reject vowels in SedolCheckDigit (#415).</action>
+    <action type="fix" dev="ggregory" due-to="sahvx655-wq, Gary Gregory">Compare exact bound in AbstractNumberValidator range checks (#416).</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>