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 8ef7b7e4f Re-validate entries in PredicatedMap/PredicatedCollection 
readObject (#682).
8ef7b7e4f is described below

commit 8ef7b7e4fc1b671ae2875d30b5c27f85097801e3
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jun 17 11:28:15 2026 +0000

    Re-validate entries in PredicatedMap/PredicatedCollection readObject
    (#682).
    
    - Sort members
    - Less vertical space
---
 src/changes/changes.xml                            |  1 +
 .../collection/PredicatedCollectionTest.java       | 18 ++++++----------
 .../collections4/map/PredicatedMapTest.java        | 24 ++++++----------------
 3 files changed, 13 insertions(+), 30 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 745516ce6..f81c6f3a6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -49,6 +49,7 @@
     <action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Reject 
non-positive entry count in bag/multiset doReadObject (#679).</action>
     <action type="fix" dev="ggregory" due-to="Dexter.k, Gary Gregory">Fix most 
Junit 5 nested tests (#681).</action>
     <action type="fix" dev="ggregory" due-to="Suhyeon Park, Gary Gregory" 
issue="COLLECTIONS-881">MultiMapUtils.getXXX ensure safe copy (#669).</action>
+    <action type="fix" dev="ggregory" due-to="Dexter.k, Gary 
Gregory">Re-validate entries in PredicatedMap/PredicatedCollection readObject 
(#682).</action>
     <!-- ADD -->
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add generics to 
UnmodifiableIterator for the wrapped type.</action>
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add a Maven 
benchmark profile for JMH.</action>
diff --git 
a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java
 
b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java
index c79847236..ad5effd7d 100644
--- 
a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java
+++ 
b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java
@@ -45,8 +45,7 @@ public class PredicatedCollectionTest<E> extends 
AbstractCollectionTest<E> {
     protected Predicate<E> testPredicate =
         String.class::isInstance;
 
-    protected Collection<E> decorateCollection(
-                final Collection<E> collection, final Predicate<E> predicate) {
+    protected Collection<E> decorateCollection(final Collection<E> collection, 
final Predicate<E> predicate) {
         return PredicatedCollection.predicatedCollection(collection, 
predicate);
     }
 
@@ -82,10 +81,13 @@ public class PredicatedCollectionTest<E> extends 
AbstractCollectionTest<E> {
         return decorateCollection(new ArrayList<>(), truePredicate);
     }
 
+    public Collection<E> makeTestCollection() {
+        return decorateCollection(new ArrayList<>(), testPredicate);
+    }
+
     @Test
     void testDeserializeRejectsElementFailingPredicate() throws Exception {
-        final PredicatedCollection<E> coll = (PredicatedCollection<E>) 
decorateCollection(
-                new ArrayList<>(), NotNullPredicate.<E>notNullPredicate());
+        final PredicatedCollection<E> coll = (PredicatedCollection<E>) 
decorateCollection(new ArrayList<>(), NotNullPredicate.<E>notNullPredicate());
         // a crafted stream can carry an element that never passed add(); 
mimic it by
         // writing one straight into the decorated collection
         coll.decorated().add(null);
@@ -100,18 +102,12 @@ public class PredicatedCollectionTest<E> extends 
AbstractCollectionTest<E> {
         });
     }
 
-    public Collection<E> makeTestCollection() {
-        return decorateCollection(new ArrayList<>(), testPredicate);
-    }
-
     @Test
     @SuppressWarnings("unchecked")
     void testIllegalAdd() {
         final Collection<E> c = makeTestCollection();
         final Integer i = 3;
-
         assertThrows(IllegalArgumentException.class, () -> c.add((E) i), 
"Integer should fail string predicate.");
-
         assertFalse(c.contains(i), "Collection shouldn't contain illegal 
element");
     }
 
@@ -124,9 +120,7 @@ public class PredicatedCollectionTest<E> extends 
AbstractCollectionTest<E> {
         elements.add((E) "two");
         elements.add((E) Integer.valueOf(3));
         elements.add((E) "four");
-
         assertThrows(IllegalArgumentException.class, () -> c.addAll(elements), 
"Integer should fail string predicate.");
-
         assertFalse(c.contains("one"), "Collection shouldn't contain illegal 
element");
         assertFalse(c.contains("two"), "Collection shouldn't contain illegal 
element");
         assertFalse(c.contains(3), "Collection shouldn't contain illegal 
element");
diff --git 
a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java 
b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java
index 462b223b4..ca3b74cee 100644
--- a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java
@@ -49,8 +49,7 @@ public class PredicatedMapTest<K, V> extends 
AbstractIterableMapTest<K, V> {
 
     protected static final Predicate<Object> testPredicate = 
String.class::isInstance;
 
-    protected IterableMap<K, V> decorateMap(final Map<K, V> map, final 
Predicate<? super K> keyPredicate,
-        final Predicate<? super V> valuePredicate) {
+    protected IterableMap<K, V> decorateMap(final Map<K, V> map, final 
Predicate<? super K> keyPredicate, final Predicate<? super V> valuePredicate) {
         return PredicatedMap.predicatedMap(map, keyPredicate, valuePredicate);
     }
 
@@ -71,8 +70,7 @@ public class PredicatedMapTest<K, V> extends 
AbstractIterableMapTest<K, V> {
     @Test
     @SuppressWarnings("unchecked")
     void testDeserializeRejectsEntryFailingPredicate() throws Exception {
-        final PredicatedMap<K, V> map = (PredicatedMap<K, V>) decorateMap(new 
HashMap<>(),
-                NotNullPredicate.notNullPredicate(), null);
+        final PredicatedMap<K, V> map = (PredicatedMap<K, V>) decorateMap(new 
HashMap<>(), NotNullPredicate.notNullPredicate(), null);
         // a crafted stream can carry an entry that never passed put(); mimic 
it by
         // writing one straight into the decorated map
         map.decorated().put(null, (V) "value");
@@ -102,31 +100,21 @@ public class PredicatedMapTest<K, V> extends 
AbstractIterableMapTest<K, V> {
     @SuppressWarnings("unchecked")
     void testPut() {
         final Map<K, V> map = makeTestMap();
-        assertThrows(IllegalArgumentException.class, () -> map.put((K) "Hi", 
(V) Integer.valueOf(3)),
-                "Illegal value should raise IllegalArgument");
-
-        assertThrows(IllegalArgumentException.class, () -> map.put((K) 
Integer.valueOf(3), (V) "Hi"),
-                "Illegal key should raise IllegalArgument");
-
+        assertThrows(IllegalArgumentException.class, () -> map.put((K) "Hi", 
(V) Integer.valueOf(3)), "Illegal value should raise IllegalArgument");
+        assertThrows(IllegalArgumentException.class, () -> map.put((K) 
Integer.valueOf(3), (V) "Hi"), "Illegal key should raise IllegalArgument");
         assertFalse(map.containsKey(Integer.valueOf(3)));
         assertFalse(map.containsValue(Integer.valueOf(3)));
-
         final Map<K, V> map2 = new HashMap<>();
         map2.put((K) "A", (V) "a");
         map2.put((K) "B", (V) "b");
         map2.put((K) "C", (V) "c");
         map2.put((K) "c", (V) Integer.valueOf(3));
-
-        assertThrows(IllegalArgumentException.class, () -> map.putAll(map2),
-                "Illegal value should raise IllegalArgument");
-
+        assertThrows(IllegalArgumentException.class, () -> map.putAll(map2), 
"Illegal value should raise IllegalArgument");
         map.put((K) "E", (V) "e");
         Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
         Map.Entry<K, V> entry = iterator.next();
         final Map.Entry<K, V> finalEntry = entry;
-        assertThrows(IllegalArgumentException.class, () -> 
finalEntry.setValue((V) Integer.valueOf(3)),
-                "Illegal value should raise IllegalArgument");
-
+        assertThrows(IllegalArgumentException.class, () -> 
finalEntry.setValue((V) Integer.valueOf(3)), "Illegal value should raise 
IllegalArgument");
         map.put((K) "F", (V) "f");
         iterator = map.entrySet().iterator();
         entry = iterator.next();

Reply via email to