8023339: Refined Collection.removeIf UOE conditions

Reviewed-by: mduigou
This commit is contained in:
Paul Sandoz 2013-09-27 13:30:31 -07:00 committed by Mike Duigou
parent e68f7e9564
commit ea739968d2
2 changed files with 12 additions and 11 deletions

View File

@ -379,8 +379,8 @@ public interface Collection<E> extends Iterable<E> {
/** /**
* Removes all of the elements of this collection that satisfy the given * Removes all of the elements of this collection that satisfy the given
* predicate. Errors or runtime exceptions thrown by the predicate are * predicate. Errors or runtime exceptions thrown during iteration or by
* relayed to the caller. * the predicate are relayed to the caller.
* *
* @implSpec * @implSpec
* The default implementation traverses all elements of the collection using * The default implementation traverses all elements of the collection using
@ -393,9 +393,10 @@ public interface Collection<E> extends Iterable<E> {
* removed * removed
* @return {@code true} if any elements were removed * @return {@code true} if any elements were removed
* @throws NullPointerException if the specified filter is null * @throws NullPointerException if the specified filter is null
* @throws UnsupportedOperationException if the {@code remove} * @throws UnsupportedOperationException if elements cannot be removed
* method is not supported by this collection's * from this collection. Implementations may throw this exception if a
* {@link #iterator} * matching element cannot be removed or if, in general, removal is not
* supported.
* @since 1.8 * @since 1.8
*/ */
default boolean removeIf(Predicate<? super E> filter) { default boolean removeIf(Predicate<? super E> filter) {

View File

@ -207,8 +207,8 @@ public class MOAT {
new Fun(){void f(){ it.next(); }}); new Fun(){void f(){ it.next(); }});
try { it.remove(); } try { it.remove(); }
catch (IllegalStateException _) { pass(); } catch (IllegalStateException ignored) { pass(); }
catch (UnsupportedOperationException _) { pass(); } catch (UnsupportedOperationException ignored) { pass(); }
catch (Throwable t) { unexpected(t); } catch (Throwable t) { unexpected(t); }
if (rnd.nextBoolean()) if (rnd.nextBoolean())
@ -280,9 +280,9 @@ public class MOAT {
testEmptyCollection(m.values()); testEmptyCollection(m.values());
try { check(! m.containsValue(null)); } try { check(! m.containsValue(null)); }
catch (NullPointerException _) { /* OK */ } catch (NullPointerException ignored) { /* OK */ }
try { check(! m.containsKey(null)); } try { check(! m.containsKey(null)); }
catch (NullPointerException _) { /* OK */ } catch (NullPointerException ignored) { /* OK */ }
check(! m.containsValue(1)); check(! m.containsValue(1));
check(! m.containsKey(1)); check(! m.containsKey(1));
} }
@ -710,8 +710,8 @@ public class MOAT {
l.addAll(-1, Collections.<Integer>emptyList()); l.addAll(-1, Collections.<Integer>emptyList());
fail("Expected IndexOutOfBoundsException not thrown"); fail("Expected IndexOutOfBoundsException not thrown");
} }
catch (UnsupportedOperationException _) {/* OK */} catch (UnsupportedOperationException ignored) {/* OK */}
catch (IndexOutOfBoundsException _) {/* OK */} catch (IndexOutOfBoundsException ignored) {/* OK */}
catch (Throwable t) { unexpected(t); } catch (Throwable t) { unexpected(t); }
// equal(l instanceof Serializable, // equal(l instanceof Serializable,