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-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new 6171ecbb1 Fix MapUtils.getIntValue(Map, K, Function) returning a byte 
(#704)
6171ecbb1 is described below

commit 6171ecbb1dc89f3e2d3bae659b6364995fbc6027
Author: Dexter.k <[email protected]>
AuthorDate: Mon Jul 6 16:55:49 2026 +0000

    Fix MapUtils.getIntValue(Map, K, Function) returning a byte (#704)
    
    * fix MapUtils.getIntValue(Map, K, Function) returning a byte
    
    * drive getShortValue function overload past byte range
---
 src/changes/changes.xml                                         | 1 +
 src/main/java/org/apache/commons/collections4/MapUtils.java     | 2 +-
 src/test/java/org/apache/commons/collections4/MapUtilsTest.java | 6 ++++--
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 53f8208db..9570715ce 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -32,6 +32,7 @@
     <action type="fix" dev="ggregory" due-to="Eric Hubert, Gary 
Gregory">Remove deprecation annotation of 
org.apache.commons.collections4.Transformer; this will be deprecated in 5.0 in 
favor of java.util.function.Function.</action>
     <action type="fix" dev="ggregory" due-to="Eric Hubert, Gary 
Gregory">Remove deprecation annotation of 
org.apache.commons.collections4.Closure; this will be deprecated in 5.0 in 
favor of java.util.function.Consumer.</action>
     <action type="fix" dev="ggregory" due-to="Sebastian Götz, Gary Gregory" 
issue="COLLECTIONS-874">MapUtils.getLongValue(Map, K, Function) returns a byte 
instead of a long.</action>
+    <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary 
Gregory">MapUtils.getIntValue(Map, K, Function) returns a byte instead of an 
int.</action>
     <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix exception 
message in 
org.apache.commons.collections4.functors.FunctorUtils.validate(Consumer...)</action>
     <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix exception 
message in 
org.apache.commons.collections4.iterators.UnmodifiableIterator.remove() to 
match java.util.Iterator.remove().</action>
     <action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz, Joerg 
Budischewski" issue="COLLECTIONS-838">Calling SetUtils.union on multiple 
instances of SetView causes JVM to hang</action>
diff --git a/src/main/java/org/apache/commons/collections4/MapUtils.java 
b/src/main/java/org/apache/commons/collections4/MapUtils.java
index 3d8d7e186..6dc8c74e7 100644
--- a/src/main/java/org/apache/commons/collections4/MapUtils.java
+++ b/src/main/java/org/apache/commons/collections4/MapUtils.java
@@ -738,7 +738,7 @@ public class MapUtils {
      */
     public static <K> int getIntValue(final Map<? super K, ?> map, final K key,
             final Function<K, Integer> defaultFunction) {
-        return applyDefaultFunction(map, key, MapUtils::getInteger, 
defaultFunction, 0).byteValue();
+        return applyDefaultFunction(map, key, MapUtils::getInteger, 
defaultFunction, 0).intValue();
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java 
b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
index c047d497d..2c3e96e63 100644
--- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
@@ -482,11 +482,13 @@ class MapUtilsTest {
     void testGetIntValue() {
         final Map<String, Integer> in = new HashMap<>();
         in.put("key", 2);
+        in.put("big", 1000);
 
         assertEquals(2, MapUtils.getIntValue(in, "key", 0), 0);
         assertEquals(2, MapUtils.getIntValue(in, "key"), 0);
         assertEquals(0, MapUtils.getIntValue(in, "noKey", 0), 0);
-        assertEquals(0, MapUtils.getIntValue(in, "noKey", key -> 0), 0);
+        assertEquals(1000, MapUtils.getIntValue(in, "big", key -> 0), 0);
+        assertEquals(Integer.MAX_VALUE, MapUtils.getIntValue(in, "noKey", key 
-> Integer.MAX_VALUE), 0);
         assertEquals(Integer.MIN_VALUE, MapUtils.getIntValue(in, "noKey", 
Integer.MIN_VALUE), 0);
         assertEquals(Integer.MAX_VALUE, MapUtils.getIntValue(in, "noKey", 
Integer.MAX_VALUE), 0);
         assertEquals(0, MapUtils.getIntValue(in, "noKey"), 0);
@@ -587,7 +589,7 @@ class MapUtilsTest {
         assertEquals(val, MapUtils.getShortValue(in, "key", val), 0);
         assertEquals(val, MapUtils.getShortValue(in, "key"), 0);
         assertEquals(val, MapUtils.getShortValue(in, "noKey", val), 0);
-        assertEquals(val, MapUtils.getShortValue(in, "noKey", key -> val), 0);
+        assertEquals(1000, MapUtils.getShortValue(in, "noKey", key -> (short) 
1000), 0);
         assertEquals(Short.MIN_VALUE, MapUtils.getShortValue(in, "noKey", 
Short.MIN_VALUE), 0);
         assertEquals(Short.MAX_VALUE, MapUtils.getShortValue(in, "noKey", 
Short.MAX_VALUE), 0);
         assertEquals(0, MapUtils.getShortValue(in, "noKey"), 0);

Reply via email to