This is an automated email from the ASF dual-hosted git repository. ggregory 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 a803af8 Collapse multiple identical catch clauses into one. a803af8 is described below commit a803af8de661dbdb436b85d4797c44ec5f3e72fd Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jan 8 09:27:03 2021 -0500 Collapse multiple identical catch clauses into one. --- .../apache/commons/collections4/IteratorUtils.java | 9 ++------- .../commons/collections4/bidimap/TreeBidiMap.java | 4 +--- .../collections4/functors/PrototypeFactory.java | 4 +--- .../collections4/map/AbstractHashedMap.java | 4 +--- .../org/apache/commons/collections4/TestUtils.java | 5 +---- .../collection/AbstractCollectionTest.java | 23 +++++++--------------- .../functors/CatchAndRethrowClosureTest.java | 2 -- .../iterators/AbstractMapIteratorTest.java | 5 +++-- .../commons/collections4/map/AbstractMapTest.java | 15 +++++++------- 9 files changed, 23 insertions(+), 48 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/IteratorUtils.java b/src/main/java/org/apache/commons/collections4/IteratorUtils.java index 751f4a3..12dbc29 100644 --- a/src/main/java/org/apache/commons/collections4/IteratorUtils.java +++ b/src/main/java/org/apache/commons/collections4/IteratorUtils.java @@ -1141,13 +1141,8 @@ public class IteratorUtils { return it; } } - } catch (final RuntimeException e) { // NOPMD - // ignore - } catch (final NoSuchMethodException e) { // NOPMD - // ignore - } catch (final IllegalAccessException e) { // NOPMD - // ignore - } catch (final InvocationTargetException e) { // NOPMD + } catch (final RuntimeException | NoSuchMethodException | IllegalAccessException | + InvocationTargetException e) { // NOPMD // ignore } return singletonIterator(obj); diff --git a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java index d363789..b42c61f 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java @@ -1381,9 +1381,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> return false; } } - } catch (final ClassCastException ex) { - return false; - } catch (final NullPointerException ex) { + } catch (final ClassCastException | NullPointerException ex) { return false; } } diff --git a/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java b/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java index 38b8bbd..90a878a 100644 --- a/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java +++ b/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java @@ -182,9 +182,7 @@ public class PrototypeFactory { final ObjectInputStream in = new ObjectInputStream(bais); return (T) in.readObject(); - } catch (final ClassNotFoundException ex) { - throw new FunctorException(ex); - } catch (final IOException ex) { + } catch (final ClassNotFoundException | IOException ex) { throw new FunctorException(ex); } finally { try { diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java index 5324f69..5e0e818 100644 --- a/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java +++ b/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java @@ -1359,9 +1359,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab } } } - } catch (final ClassCastException ignored) { - return false; - } catch (final NullPointerException ignored) { + } catch (final ClassCastException | NullPointerException ignored) { return false; } return true; diff --git a/src/test/java/org/apache/commons/collections4/TestUtils.java b/src/test/java/org/apache/commons/collections4/TestUtils.java index 00a7d9f..da92660 100644 --- a/src/test/java/org/apache/commons/collections4/TestUtils.java +++ b/src/test/java/org/apache/commons/collections4/TestUtils.java @@ -58,10 +58,7 @@ public final class TestUtils { // assert that original object and deserialized objects are the same assertSame(msg, o, object); - } catch (final IOException e) { - // should never happen - throw new RuntimeException(e); - } catch (final ClassNotFoundException e) { + } catch (final IOException | ClassNotFoundException e) { // should never happen throw new RuntimeException(e); } diff --git a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java index eed7494..1ff67be 100644 --- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java @@ -1274,10 +1274,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest { getCollection().clear(); iter.next(); fail("next after clear should raise ConcurrentModification"); - } catch (final ConcurrentModificationException e) { - // expected - } catch (final NoSuchElementException e) { - // (also legal given spec) + } catch (final ConcurrentModificationException | NoSuchElementException e) { + // ConcurrentModificationException: expected + // NoSuchElementException: (also legal given spec) } resetFull(); @@ -1387,9 +1386,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest { protected static void assertNotCollectionContains(final Collection<?> coll, final Object element) { try { assertFalse(coll.contains(element)); - } catch (final ClassCastException e) { - //apparently not - } catch (final NullPointerException e) { + } catch (final ClassCastException | NullPointerException e) { //apparently not } } @@ -1402,9 +1399,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest { protected static void assertNotCollectionContainsAll(final Collection<?> coll, final Collection<?> sub) { try { assertFalse(coll.containsAll(sub)); - } catch (final ClassCastException cce) { - //apparently not - } catch (final NullPointerException e) { + } catch (final ClassCastException | NullPointerException e) { //apparently not } } @@ -1417,9 +1412,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest { protected static void assertNotRemoveFromCollection(final Collection<?> coll, final Object element) { try { assertFalse(coll.remove(element)); - } catch (final ClassCastException cce) { - //apparently not - } catch (final NullPointerException e) { + } catch (final ClassCastException | NullPointerException e) { //apparently not } } @@ -1432,9 +1425,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest { protected static void assertNotRemoveAllFromCollection(final Collection<?> coll, final Collection<?> sub) { try { assertFalse(coll.removeAll(sub)); - } catch (final ClassCastException cce) { - //apparently not - } catch (final NullPointerException e) { + } catch (final ClassCastException | NullPointerException e) { //apparently not } } diff --git a/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java b/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java index 3f72400..a3ea134 100644 --- a/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java +++ b/src/test/java/org/apache/commons/collections4/functors/CatchAndRethrowClosureTest.java @@ -64,8 +64,6 @@ public class CatchAndRethrowClosureTest extends AbstractClosureTest { Closure<Integer> closure = generateNoExceptionClosure(); try { closure.execute(Integer.valueOf(0)); - } catch (final FunctorException ex) { - Assert.fail(); } catch (final RuntimeException ex) { Assert.fail(); } diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java index 775801c..671a95c 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java @@ -141,8 +141,9 @@ public abstract class AbstractMapIteratorTest<K, V> extends AbstractIteratorTest try { it.setValue(addSetValues()[0]); fail(); - } catch (final UnsupportedOperationException ex) { - } catch (final IllegalStateException ex) {} + } catch (final UnsupportedOperationException | IllegalStateException ex) { + // ignore + } } else { // setValue() should throw an IllegalStateException try { diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java index 029a8d2..95280dc 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java @@ -832,8 +832,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest { // two possible exception here, either valid getMap().put(keys[0], newValues[0]); fail("Expected IllegalArgumentException or UnsupportedOperationException on put (change)"); - } catch (final IllegalArgumentException ex) { - } catch (final UnsupportedOperationException ex) {} + } catch (final IllegalArgumentException | UnsupportedOperationException ex) { + // ignore + } } } else if (isPutChangeSupported()) { @@ -841,8 +842,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest { try { getMap().put(keys[0], values[0]); fail("Expected UnsupportedOperationException or IllegalArgumentException on put (add) when fixed size"); - } catch (final IllegalArgumentException ex) { - } catch (final UnsupportedOperationException ex) { + } catch (final IllegalArgumentException | UnsupportedOperationException ex) { + // ignore } resetFull(); @@ -887,8 +888,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest { try { getMap().put(null, values[0]); fail("put(null, value) should throw NPE/IAE"); - } catch (final NullPointerException ex) { - } catch (final IllegalArgumentException ex) {} + } catch (final NullPointerException | IllegalArgumentException ex) {} } } } @@ -907,8 +907,7 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest { try { getMap().put(keys[0], null); fail("put(key, null) should throw NPE/IAE"); - } catch (final NullPointerException ex) { - } catch (final IllegalArgumentException ex) {} + } catch (final NullPointerException | IllegalArgumentException ex) {} } } }