Collapse multiple identical catch clauses into one.

This commit is contained in:
Gary Gregory 2021-01-08 09:27:03 -05:00
parent e21ed0b99b
commit a803af8de6
9 changed files with 23 additions and 48 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;

View File

@ -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);
}

View File

@ -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
}
}

View File

@ -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();
}

View File

@ -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 {

View File

@ -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) {}
}
}
}