You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ki...@apache.org on 2021/10/09 01:53:45 UTC

[commons-collections] branch master updated (dfafc5d -> 5b0f22a)

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

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


    from dfafc5d  Merge branch 'pr-255'
     new cbc5db5  [COLLECTIONS-799]: Prevent modifications by pollFirst and pollLast
     new e6f72fe  [COLLECTIONS-799] Changelog
     new 5b0f22a  Merge branch 'pr-250'

The 3 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:
 pom.xml                                            |  3 ++
 src/changes/changes.xml                            |  3 ++
 .../collections4/set/UnmodifiableNavigableSet.java | 16 ++++++
 .../set/UnmodifiableNavigableSetTest.java          | 60 +++++++---------------
 4 files changed, 40 insertions(+), 42 deletions(-)

[commons-collections] 01/03: [COLLECTIONS-799]: Prevent modifications by pollFirst and pollLast

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cbc5db55408dae5d8744307a5eb379df36d55427
Author: Stefano Cordio <st...@gmail.com>
AuthorDate: Tue Sep 7 23:21:41 2021 +0200

    [COLLECTIONS-799]: Prevent modifications by pollFirst and pollLast
---
 pom.xml                                            |  3 ++
 .../collections4/set/UnmodifiableNavigableSet.java | 16 ++++++
 .../set/UnmodifiableNavigableSetTest.java          | 60 +++++++---------------
 3 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/pom.xml b/pom.xml
index 02272cd..ad4348e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -455,6 +455,9 @@
     <contributor>
       <name>Chen Guoping</name>
     </contributor>
+    <contributor>
+      <name>Stefano Cordio</name>
+    </contributor>
   </contributors>
 
   <dependencies>
diff --git a/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java b/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java
index 48bfe39..fcdc5b6 100644
--- a/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java
+++ b/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java
@@ -107,6 +107,22 @@ public final class UnmodifiableNavigableSet<E>
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * @since 4.5
+     */
+    @Override
+    public E pollFirst() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @since 4.5
+     */
+    @Override
+    public E pollLast() {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public boolean retainAll(final Collection<?> coll) {
         throw new UnsupportedOperationException();
diff --git a/src/test/java/org/apache/commons/collections4/set/UnmodifiableNavigableSetTest.java b/src/test/java/org/apache/commons/collections4/set/UnmodifiableNavigableSetTest.java
index d335994..51e3792 100644
--- a/src/test/java/org/apache/commons/collections4/set/UnmodifiableNavigableSetTest.java
+++ b/src/test/java/org/apache/commons/collections4/set/UnmodifiableNavigableSetTest.java
@@ -27,6 +27,8 @@ import junit.framework.Test;
 
 import org.apache.commons.collections4.BulkTest;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 /**
  * Extension of {@link AbstractNavigableSetTest} for exercising the
  * {@link UnmodifiableNavigableSet} implementation.
@@ -48,7 +50,7 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
     //-------------------------------------------------------------------
     @Override
     public NavigableSet<E> makeObject() {
-        return UnmodifiableNavigableSet.unmodifiableNavigableSet(new TreeSet<E>());
+        return UnmodifiableNavigableSet.unmodifiableNavigableSet(new TreeSet<>());
     }
 
     @Override
@@ -95,11 +97,7 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
     public void testDecorateFactory() {
         final NavigableSet<E> set = makeFullCollection();
         assertSame(set, UnmodifiableNavigableSet.unmodifiableNavigableSet(set));
-
-        try {
-            UnmodifiableNavigableSet.unmodifiableNavigableSet(null);
-            fail();
-        } catch (final NullPointerException ex) {}
+        assertThrows(NullPointerException.class, () -> UnmodifiableNavigableSet.unmodifiableNavigableSet(null));
     }
 
     /**
@@ -107,48 +105,26 @@ public class UnmodifiableNavigableSetTest<E> extends AbstractNavigableSetTest<E>
      */
     @SuppressWarnings("unchecked")
     public void verifyUnmodifiable(final Set<E> set) {
-        try {
-            set.add((E) "value");
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
-        }
-        try {
-            set.addAll(new TreeSet<E>());
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
-        }
-        try {
-            set.clear();
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
-        }
-        try {
-            set.remove("x");
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
-        }
-        try {
-            set.removeAll(array);
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
-        }
-        try {
-            set.retainAll(array);
-            fail("Expecting UnsupportedOperationException.");
-        } catch (final UnsupportedOperationException e) {
-            // expected
+        assertThrows(UnsupportedOperationException.class, () -> set.add((E) "value"));
+        assertThrows(UnsupportedOperationException.class, () -> set.addAll(new TreeSet<>()));
+        assertThrows(UnsupportedOperationException.class, () -> set.clear());
+        assertThrows(UnsupportedOperationException.class, () -> set.iterator().remove());
+        assertThrows(UnsupportedOperationException.class, () -> set.remove("x"));
+        assertThrows(UnsupportedOperationException.class, () -> set.removeAll(array));
+        assertThrows(UnsupportedOperationException.class, () -> set.removeIf(element -> true));
+        assertThrows(UnsupportedOperationException.class, () -> set.retainAll(array));
+
+        if (set instanceof NavigableSet) {
+            final NavigableSet<E> navigableSet = (NavigableSet<E>) set;
+            assertThrows(UnsupportedOperationException.class, () -> navigableSet.pollFirst());
+            assertThrows(UnsupportedOperationException.class, () -> navigableSet.pollLast());
         }
     }
 
     public void testComparator() {
         setupSet();
         final Comparator<? super E> c = set.comparator();
-        assertTrue("natural order, so comparator should be null", c == null);
+        assertNull("natural order, so comparator should be null", c);
     }
 
 

[commons-collections] 02/03: [COLLECTIONS-799] Changelog

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e6f72fe910990913401173e02ac33d5b85b5d775
Author: Bruno P. Kinoshita <ki...@users.noreply.github.com>
AuthorDate: Sat Oct 9 14:53:13 2021 +1300

    [COLLECTIONS-799] Changelog
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9e20e5d..1cf9dd6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -79,6 +79,9 @@
     <action issue="COLLECTIONS-796" type="fix" dev="kinow" due-to="Clemens Kurz">
       SetUniqueList.createSetBasedOnList doesn't add list elements to return value.
     </action>
+    <action issue="COLLECTIONS-799" type="fix" dev="kinow" due-to="Stefano Cordio">
+      UnmodifiableNavigableSet can be modified by pollFirst() and pollLast().
+    </action>
     <!-- ADD -->
     <action issue="COLLECTIONS-760" dev="kinow" type="add" due-to="Isira Seneviratne">
       Add tests for MapUtils.

[commons-collections] 03/03: Merge branch 'pr-250'

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5b0f22a750450db1b84da27a927147c90630ffd0
Merge: dfafc5d e6f72fe
Author: Bruno P. Kinoshita <ki...@users.noreply.github.com>
AuthorDate: Sat Oct 9 14:53:22 2021 +1300

    Merge branch 'pr-250'
    
    This closes #250

 pom.xml                                            |  3 ++
 src/changes/changes.xml                            |  3 ++
 .../collections4/set/UnmodifiableNavigableSet.java | 16 ++++++
 .../set/UnmodifiableNavigableSetTest.java          | 60 +++++++---------------
 4 files changed, 40 insertions(+), 42 deletions(-)