diff --git a/src/java.base/share/classes/java/util/ArrayList.java b/src/java.base/share/classes/java/util/ArrayList.java --- a/src/java.base/share/classes/java/util/ArrayList.java +++ b/src/java.base/share/classes/java/util/ArrayList.java @@ -1550,7 +1550,6 @@ setBit(deathRow, i - beg); if (modCount != expectedModCount) throw new ConcurrentModificationException(); - expectedModCount++; modCount++; int w = beg; for (i = beg; i < end; i++) diff --git a/src/java.base/share/classes/java/util/Vector.java b/src/java.base/share/classes/java/util/Vector.java --- a/src/java.base/share/classes/java/util/Vector.java +++ b/src/java.base/share/classes/java/util/Vector.java @@ -1023,7 +1023,6 @@ setBit(deathRow, i - beg); if (modCount != expectedModCount) throw new ConcurrentModificationException(); - expectedModCount++; modCount++; int w = beg; for (i = beg; i < end; i++) diff --git a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java --- a/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java +++ b/src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java @@ -245,8 +245,7 @@ Future f = futures.get(i); if (!f.isDone()) { try { f.get(); } - catch (CancellationException ignore) {} - catch (ExecutionException ignore) {} + catch (CancellationException | ExecutionException ignore) {} } } return futures; @@ -283,8 +282,7 @@ Future f = futures.get(j); if (!f.isDone()) { try { f.get(deadline - System.nanoTime(), NANOSECONDS); } - catch (CancellationException ignore) {} - catch (ExecutionException ignore) {} + catch (CancellationException | ExecutionException ignore) {} catch (TimeoutException timedOut) { break timedOut; } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -717,12 +717,12 @@ */ static Class comparableClassFor(Object x) { if (x instanceof Comparable) { - Class c; Type[] ts, as; Type t; ParameterizedType p; + Class c; Type[] ts, as; ParameterizedType p; if ((c = x.getClass()) == String.class) // bypass checks return c; if ((ts = c.getGenericInterfaces()) != null) { - for (int i = 0; i < ts.length; ++i) { - if (((t = ts[i]) instanceof ParameterizedType) && + for (Type t : ts) { + if ((t instanceof ParameterizedType) && ((p = (ParameterizedType)t).getRawType() == Comparable.class) && (as = p.getActualTypeArguments()) != null && @@ -2328,15 +2328,15 @@ * @param check if <0, don't check resize, if <= 1 only check if uncontended */ private final void addCount(long x, int check) { - CounterCell[] as; long b, s; - if ((as = counterCells) != null || + CounterCell[] cs; long b, s; + if ((cs = counterCells) != null || !U.compareAndSetLong(this, BASECOUNT, b = baseCount, s = b + x)) { - CounterCell a; long v; int m; + CounterCell c; long v; int m; boolean uncontended = true; - if (as == null || (m = as.length - 1) < 0 || - (a = as[ThreadLocalRandom.getProbe() & m]) == null || + if (cs == null || (m = cs.length - 1) < 0 || + (c = cs[ThreadLocalRandom.getProbe() & m]) == null || !(uncontended = - U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x))) { + U.compareAndSetLong(c, CELLVALUE, v = c.value, v + x))) { fullAddCount(x, uncontended); return; } @@ -2574,13 +2574,12 @@ } final long sumCount() { - CounterCell[] as = counterCells; CounterCell a; + CounterCell[] cs = counterCells; long sum = baseCount; - if (as != null) { - for (int i = 0; i < as.length; ++i) { - if ((a = as[i]) != null) - sum += a.value; - } + if (cs != null) { + for (CounterCell c : cs) + if (c != null) + sum += c.value; } return sum; } @@ -2595,9 +2594,9 @@ } boolean collide = false; // True if last slot nonempty for (;;) { - CounterCell[] as; CounterCell a; int n; long v; - if ((as = counterCells) != null && (n = as.length) > 0) { - if ((a = as[(n - 1) & h]) == null) { + CounterCell[] cs; CounterCell c; int n; long v; + if ((cs = counterCells) != null && (n = cs.length) > 0) { + if ((c = cs[(n - 1) & h]) == null) { if (cellsBusy == 0) { // Try to attach new Cell CounterCell r = new CounterCell(x); // Optimistic create if (cellsBusy == 0 && @@ -2623,21 +2622,17 @@ } else if (!wasUncontended) // CAS already known to fail wasUncontended = true; // Continue after rehash - else if (U.compareAndSetLong(a, CELLVALUE, v = a.value, v + x)) + else if (U.compareAndSetLong(c, CELLVALUE, v = c.value, v + x)) break; - else if (counterCells != as || n >= NCPU) + else if (counterCells != cs || n >= NCPU) collide = false; // At max size or stale else if (!collide) collide = true; else if (cellsBusy == 0 && U.compareAndSetInt(this, CELLSBUSY, 0, 1)) { try { - if (counterCells == as) {// Expand table unless stale - CounterCell[] rs = new CounterCell[n << 1]; - for (int i = 0; i < n; ++i) - rs[i] = as[i]; - counterCells = rs; - } + if (counterCells == cs) // Expand table unless stale + counterCells = Arrays.copyOf(cs, n << 1); } finally { cellsBusy = 0; } @@ -2646,11 +2641,11 @@ } h = ThreadLocalRandom.advanceProbe(h); } - else if (cellsBusy == 0 && counterCells == as && + else if (cellsBusy == 0 && counterCells == cs && U.compareAndSetInt(this, CELLSBUSY, 0, 1)) { boolean init = false; try { // Initialize table - if (counterCells == as) { + if (counterCells == cs) { CounterCell[] rs = new CounterCell[2]; rs[h & 1] = new CounterCell(x); counterCells = rs; diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -2204,9 +2204,7 @@ Collection c = (Collection) o; try { return containsAll(c) && c.containsAll(this); - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { + } catch (ClassCastException | NullPointerException unused) { return false; } } @@ -2331,9 +2329,7 @@ Collection c = (Collection) o; try { return containsAll(c) && c.containsAll(this); - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { + } catch (ClassCastException | NullPointerException unused) { return false; } } @@ -2453,9 +2449,7 @@ if (k == null) // pass by markers and headers return true; int c = cpr(cmp, k, hi); - if (c > 0 || (c == 0 && !hiInclusive)) - return false; - return true; + return c < 0 || (c == 0 && hiInclusive); } /** diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListSet.java @@ -309,9 +309,7 @@ Collection c = (Collection) o; try { return containsAll(c) && c.containsAll(this); - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { + } catch (ClassCastException | NullPointerException unused) { return false; } } diff --git a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java --- a/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java +++ b/src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java @@ -508,7 +508,7 @@ public boolean remove(Object o) { Object[] snapshot = getArray(); int index = indexOf(o, snapshot, 0, snapshot.length); - return (index < 0) ? false : remove(o, snapshot, index); + return index >= 0 && remove(o, snapshot, index); } /** @@ -587,8 +587,8 @@ */ public boolean addIfAbsent(E e) { Object[] snapshot = getArray(); - return indexOf(e, snapshot, 0, snapshot.length) >= 0 ? false : - addIfAbsent(e, snapshot); + return indexOf(e, snapshot, 0, snapshot.length) < 0 + && addIfAbsent(e, snapshot); } /** @@ -980,13 +980,10 @@ List list = (List)o; Iterator it = list.iterator(); - Object[] elements = getArray(); - for (int i = 0, len = elements.length; i < len; i++) - if (!it.hasNext() || !Objects.equals(elements[i], it.next())) + for (Object element : getArray()) + if (!it.hasNext() || !Objects.equals(element, it.next())) return false; - if (it.hasNext()) - return false; - return true; + return !it.hasNext(); } /** diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java @@ -1353,17 +1353,16 @@ @SuppressWarnings("unchecked") private boolean bulkRemove(Predicate filter) { boolean removed = false; + final ReentrantLock lock = this.lock; Node p = null; - final ReentrantLock lock = this.lock; Node[] nodes = null; int n, len = 0; do { // 1. Extract batch of up to 64 elements while holding the lock. - long deathRow = 0; // "bitset" of size 64 lock.lock(); try { - if (nodes == null) { - if (p == null) p = first; + if (nodes == null) { // first batch; initialize + p = first; for (Node q = p; q != null; q = succ(q)) if (q.item != null && ++len == 64) break; @@ -1376,6 +1375,7 @@ } // 2. Run the filter on the elements while lock is free. + long deathRow = 0L; // "bitset" of size 64 for (int i = 0; i < n; i++) { final E e; if ((e = nodes[i].item) != null && filter.test(e)) @@ -1393,6 +1393,7 @@ unlink(q); removed = true; } + nodes[i] = null; // help GC } } finally { lock.unlock(); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java --- a/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java @@ -1060,11 +1060,10 @@ int n, len = 0; do { // 1. Extract batch of up to 64 elements while holding the lock. - long deathRow = 0; // "bitset" of size 64 fullyLock(); try { - if (nodes == null) { - if (p == null) p = head.next; + if (nodes == null) { // first batch; initialize + p = head.next; for (Node q = p; q != null; q = succ(q)) if (q.item != null && ++len == 64) break; @@ -1077,6 +1076,7 @@ } // 2. Run the filter on the elements while lock is free. + long deathRow = 0L; // "bitset" of size 64 for (int i = 0; i < n; i++) { final E e; if ((e = nodes[i].item) != null && filter.test(e)) @@ -1095,6 +1095,7 @@ unlink(q, ancestor); removed = true; } + nodes[i] = null; // help GC } } finally { fullyUnlock(); diff --git a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java --- a/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/LinkedTransferQueue.java @@ -772,9 +772,8 @@ Node first = null; restartFromHead: for (;;) { Node h = head, p = h; - for (; p != null;) { - final Object item; - if ((item = p.item) != null) { + while (p != null) { + if (p.item != null) { if (p.isData) { first = p; break; @@ -1602,8 +1601,7 @@ // Read in elements until trailing null sentinel found Node h = null, t = null; for (Object item; (item = s.readObject()) != null; ) { - @SuppressWarnings("unchecked") - Node newNode = new Node((E) item); + Node newNode = new Node(item); if (h == null) h = t = newNode; else diff --git a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java --- a/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java +++ b/src/java.base/share/classes/java/util/concurrent/PriorityBlockingQueue.java @@ -269,8 +269,8 @@ if (a.getClass() != Object[].class) a = Arrays.copyOf(a, n, Object[].class); if (screen && (n == 1 || this.comparator != null)) { - for (int i = 0; i < n; ++i) - if (a[i] == null) + for (Object elt : a) + if (elt == null) throw new NullPointerException(); } this.queue = a; diff --git a/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java b/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java --- a/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java +++ b/src/java.base/share/classes/java/util/concurrent/SubmissionPublisher.java @@ -753,8 +753,10 @@ else pred.next = next; } - else + else { subs.add(b.subscriber); + pred = b; + } } } return subs; diff --git a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java --- a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java +++ b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java @@ -67,7 +67,7 @@ * {@code ThreadLocalRandom.current().nextX(...)} (where * {@code X} is {@code Int}, {@code Long}, etc). * When all usages are of this form, it is never possible to - * accidently share a {@code ThreadLocalRandom} across multiple threads. + * accidentally share a {@code ThreadLocalRandom} across multiple threads. * *

This class also provides additional commonly used bounded random * generation methods. diff --git a/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java b/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java --- a/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java +++ b/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java @@ -264,13 +264,12 @@ * assist in storage reclamation when large numbers of queued tasks * become cancelled. * - *

Finalization
+ *
Reclamation
* *
A pool that is no longer referenced in a program AND - * has no remaining threads will be {@code shutdown} automatically. If - * you would like to ensure that unreferenced pools are reclaimed even - * if users forget to call {@link #shutdown}, then you must arrange - * that unused threads eventually die, by setting appropriate + * has no remaining threads may be reclaimed (garbage collected) + * without being explicity shutdown. You can configure a pool to allow + * all unused threads to eventually die by setting appropriate * keep-alive times, using a lower bound of zero core threads and/or * setting {@link #allowCoreThreadTimeOut(boolean)}.
* @@ -361,7 +360,7 @@ * time, but need not hit each state. The transitions are: * * RUNNING -> SHUTDOWN - * On invocation of shutdown(), perhaps implicitly in finalize() + * On invocation of shutdown() * (RUNNING or SHUTDOWN) -> STOP * On invocation of shutdownNow() * SHUTDOWN -> TIDYING @@ -581,9 +580,6 @@ private static final RuntimePermission shutdownPerm = new RuntimePermission("modifyThread"); - /** The context to be used when executing the finalizer, or null. */ - private final AccessControlContext acc; - /** * Class Worker mainly maintains interrupt control state for * threads running tasks, along with other minor bookkeeping. @@ -1300,9 +1296,6 @@ throw new IllegalArgumentException(); if (workQueue == null || threadFactory == null || handler == null) throw new NullPointerException(); - this.acc = (System.getSecurityManager() == null) - ? null - : AccessController.getContext(); this.corePoolSize = corePoolSize; this.maximumPoolSize = maximumPoolSize; this.workQueue = workQueue; @@ -1470,33 +1463,6 @@ } /** - * Invokes {@code shutdown} when this executor is no longer - * referenced and it has no threads. - * - *

This method is invoked with privileges that are restricted by - * the security context of the caller that invokes the constructor. - * - * @deprecated The {@code finalize} method has been deprecated. - * Subclasses that override {@code finalize} in order to perform cleanup - * should be modified to use alternative cleanup mechanisms and - * to remove the overriding {@code finalize} method. - * When overriding the {@code finalize} method, its implementation must explicitly - * ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}. - * See the specification for {@link Object#finalize()} for further - * information about migration options. - */ - @Deprecated(since="9") - protected void finalize() { - SecurityManager sm = System.getSecurityManager(); - if (sm == null || acc == null) { - shutdown(); - } else { - PrivilegedAction pa = () -> { shutdown(); return null; }; - AccessController.doPrivileged(pa, acc); - } - } - - /** * Sets the thread factory used to create new threads. * * @param threadFactory the new thread factory diff --git a/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java b/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java --- a/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java +++ b/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java @@ -320,7 +320,9 @@ // predNext is the apparent node to unsplice. CASes below will // fail if not, in which case, we lost race vs another cancel - // or signal, so no further action is necessary. + // or signal, so no further action is necessary, although with + // a possibility that a cancelled node may transiently remain + // reachable. Node predNext = pred.next; // Can use unconditional write instead of CAS here. @@ -912,13 +914,13 @@ * at any time, a {@code true} return does not guarantee that any * other thread will ever acquire. * - *

In this implementation, this operation returns in - * constant time. - * * @return {@code true} if there may be other threads waiting to acquire */ public final boolean hasQueuedThreads() { - return head != tail; + for (Node p = tail, h = head; p != h && p != null; p = p.prev) + if (p.waitStatus <= 0) + return true; + return false; } /** @@ -1067,16 +1069,20 @@ * @since 1.7 */ public final boolean hasQueuedPredecessors() { - // The correctness of this depends on head being initialized - // before tail and on head.next being accurate if the current - // thread is first in queue. - Node t = tail; // Read fields in reverse initialization order - Node h = head; - Node s; - return h != t && - ((s = h.next) == null || s.thread != Thread.currentThread()); + Node h, s; + if ((h = head) != null) { + if ((s = h.next) == null || s.waitStatus > 0) { + s = null; // traverse in case of concurrent cancellation + for (Node p = tail; p != h && p != null; p = p.prev) { + if (p.waitStatus <= 0) + s = p; } - + } + if (s != null && s.thread != Thread.currentThread()) + return true; + } + return false; + } // Instrumentation and monitoring methods diff --git a/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java b/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java --- a/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java +++ b/src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java @@ -800,7 +800,9 @@ // predNext is the apparent node to unsplice. CASes below will // fail if not, in which case, we lost race vs another cancel - // or signal, so no further action is necessary. + // or signal, so no further action is necessary, although with + // a possibility that a cancelled node may transiently remain + // reachable. Node predNext = pred.next; // Can use unconditional write instead of CAS here. @@ -1392,13 +1394,13 @@ * at any time, a {@code true} return does not guarantee that any * other thread will ever acquire. * - *

In this implementation, this operation returns in - * constant time. - * * @return {@code true} if there may be other threads waiting to acquire */ public final boolean hasQueuedThreads() { - return head != tail; + for (Node p = tail, h = head; p != h && p != null; p = p.prev) + if (p.waitStatus <= 0) + return true; + return false; } /** @@ -1547,16 +1549,20 @@ * @since 1.7 */ public final boolean hasQueuedPredecessors() { - // The correctness of this depends on head being initialized - // before tail and on head.next being accurate if the current - // thread is first in queue. - Node t = tail; // Read fields in reverse initialization order - Node h = head; - Node s; - return h != t && - ((s = h.next) == null || s.thread != Thread.currentThread()); + Node h, s; + if ((h = head) != null) { + if ((s = h.next) == null || s.waitStatus > 0) { + s = null; // traverse in case of concurrent cancellation + for (Node p = tail; p != h && p != null; p = p.prev) { + if (p.waitStatus <= 0) + s = p; } - + } + if (s != null && s.thread != Thread.currentThread()) + return true; + } + return false; + } // Instrumentation and monitoring methods diff --git a/test/jdk/java/util/AbstractCollection/ToString.java b/test/jdk/java/util/AbstractCollection/ToString.java --- a/test/jdk/java/util/AbstractCollection/ToString.java +++ b/test/jdk/java/util/AbstractCollection/ToString.java @@ -29,8 +29,13 @@ * @author Josh Bloch, Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.AbstractCollection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.Vector; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; public class ToString { private static void realMain(String[] args) { diff --git a/test/jdk/java/util/AbstractList/CheckForComodification.java b/test/jdk/java/util/AbstractList/CheckForComodification.java --- a/test/jdk/java/util/AbstractList/CheckForComodification.java +++ b/test/jdk/java/util/AbstractList/CheckForComodification.java @@ -30,7 +30,9 @@ * @ignore Bug fix temporarily removed as it uncovered other bugs (4992226) */ -import java.util.*; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.List; public class CheckForComodification { private static final int LENGTH = 10; diff --git a/test/jdk/java/util/AbstractList/FailFastIterator.java b/test/jdk/java/util/AbstractList/FailFastIterator.java --- a/test/jdk/java/util/AbstractList/FailFastIterator.java +++ b/test/jdk/java/util/AbstractList/FailFastIterator.java @@ -28,7 +28,10 @@ * *after* the set/add/remove operations were performed. */ -import java.util.*; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.List; +import java.util.ListIterator; public class FailFastIterator { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/AbstractList/HasNextAfterException.java b/test/jdk/java/util/AbstractList/HasNextAfterException.java --- a/test/jdk/java/util/AbstractList/HasNextAfterException.java +++ b/test/jdk/java/util/AbstractList/HasNextAfterException.java @@ -30,7 +30,10 @@ * @author Konstantin Kladko */ -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; public class HasNextAfterException { public static void main(String[] args) { diff --git a/test/jdk/java/util/AbstractMap/AbstractMapClone.java b/test/jdk/java/util/AbstractMap/AbstractMapClone.java --- a/test/jdk/java/util/AbstractMap/AbstractMapClone.java +++ b/test/jdk/java/util/AbstractMap/AbstractMapClone.java @@ -30,7 +30,10 @@ * @author Konstantin Kladko */ -import java.util.*; +import java.util.AbstractMap; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; public class AbstractMapClone extends AbstractMap implements Cloneable { diff --git a/test/jdk/java/util/AbstractMap/Equals.java b/test/jdk/java/util/AbstractMap/Equals.java --- a/test/jdk/java/util/AbstractMap/Equals.java +++ b/test/jdk/java/util/AbstractMap/Equals.java @@ -21,7 +21,12 @@ * questions. */ -import java.util.*; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; /** * @test diff --git a/test/jdk/java/util/AbstractMap/SimpleEntries.java b/test/jdk/java/util/AbstractMap/SimpleEntries.java --- a/test/jdk/java/util/AbstractMap/SimpleEntries.java +++ b/test/jdk/java/util/AbstractMap/SimpleEntries.java @@ -28,9 +28,10 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; -import static java.util.AbstractMap.*; +import java.util.Map; + +import static java.util.AbstractMap.SimpleEntry; +import static java.util.AbstractMap.SimpleImmutableEntry; public class SimpleEntries { private static String k = "foo"; diff --git a/test/jdk/java/util/AbstractMap/ToString.java b/test/jdk/java/util/AbstractMap/ToString.java --- a/test/jdk/java/util/AbstractMap/ToString.java +++ b/test/jdk/java/util/AbstractMap/ToString.java @@ -29,7 +29,8 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; public class ToString { public static void main(String[] args) { diff --git a/test/jdk/java/util/AbstractSequentialList/AddAll.java b/test/jdk/java/util/AbstractSequentialList/AddAll.java --- a/test/jdk/java/util/AbstractSequentialList/AddAll.java +++ b/test/jdk/java/util/AbstractSequentialList/AddAll.java @@ -27,7 +27,11 @@ * @summary AddAll(int, Collection) intersperses the Collection with this List. */ -import java.util.*; +import java.util.AbstractSequentialList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ListIterator; public class AddAll { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/ArrayList/AddAll.java b/test/jdk/java/util/ArrayList/AddAll.java --- a/test/jdk/java/util/ArrayList/AddAll.java +++ b/test/jdk/java/util/ArrayList/AddAll.java @@ -28,7 +28,12 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Vector; +import java.util.WeakHashMap; public class AddAll { public static void main(String[] args) { diff --git a/test/jdk/java/util/ArrayList/Bug6533203.java b/test/jdk/java/util/ArrayList/Bug6533203.java --- a/test/jdk/java/util/ArrayList/Bug6533203.java +++ b/test/jdk/java/util/ArrayList/Bug6533203.java @@ -27,7 +27,9 @@ * @summary AbstractList.ListItr.add might corrupt iterator state if enclosing add throws */ -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; @SuppressWarnings({"serial","unchecked"}) public class Bug6533203 { diff --git a/test/jdk/java/util/ArrayList/IteratorMicroBenchmark.java b/test/jdk/java/util/ArrayList/IteratorMicroBenchmark.java --- a/test/jdk/java/util/ArrayList/IteratorMicroBenchmark.java +++ b/test/jdk/java/util/ArrayList/IteratorMicroBenchmark.java @@ -27,9 +27,12 @@ * @run main IteratorMicroBenchmark iterations=1 size=8 warmup=0 */ +import static java.util.stream.Collectors.toList; + import java.lang.ref.WeakReference; import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; import java.util.List; @@ -165,16 +168,11 @@ } private static Job[] filter(Pattern filter, Job[] jobs) { - if (filter == null) return jobs; - Job[] newJobs = new Job[jobs.length]; - int n = 0; - for (Job job : jobs) - if (filter.matcher(job.name()).find()) - newJobs[n++] = job; - // Arrays.copyOf not available in JDK 5 - Job[] ret = new Job[n]; - System.arraycopy(newJobs, 0, ret, 0, n); - return ret; + return (filter == null) ? jobs + : Arrays.stream(jobs) + .filter(job -> filter.matcher(job.name()).find()) + .collect(toList()) + .toArray(new Job[0]); } private static void deoptimize(int sum) { diff --git a/test/jdk/java/util/ArrayList/RangeCheckMicroBenchmark.java b/test/jdk/java/util/ArrayList/RangeCheckMicroBenchmark.java --- a/test/jdk/java/util/ArrayList/RangeCheckMicroBenchmark.java +++ b/test/jdk/java/util/ArrayList/RangeCheckMicroBenchmark.java @@ -32,9 +32,14 @@ * @author Martin Buchholz */ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.CountDownLatch; import java.util.regex.Pattern; -import java.util.concurrent.CountDownLatch; + +import static java.util.stream.Collectors.toList; public class RangeCheckMicroBenchmark { abstract static class Job { @@ -133,16 +138,11 @@ } private static Job[] filter(Pattern filter, Job[] jobs) { - if (filter == null) return jobs; - Job[] newJobs = new Job[jobs.length]; - int n = 0; - for (Job job : jobs) - if (filter.matcher(job.name()).find()) - newJobs[n++] = job; - // Arrays.copyOf not available in JDK 5 - Job[] ret = new Job[n]; - System.arraycopy(newJobs, 0, ret, 0, n); - return ret; + return (filter == null) ? jobs + : Arrays.stream(jobs) + .filter(job -> filter.matcher(job.name()).find()) + .collect(toList()) + .toArray(new Job[0]); } private static void deoptimize(ArrayList list) { diff --git a/test/jdk/java/util/Collection/BiggernYours.java b/test/jdk/java/util/Collection/BiggernYours.java --- a/test/jdk/java/util/Collection/BiggernYours.java +++ b/test/jdk/java/util/Collection/BiggernYours.java @@ -28,9 +28,27 @@ * @author Martin Buchholz */ -import java.io.*; -import java.util.*; -import java.util.concurrent.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.Objects; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.LinkedTransferQueue; +import java.util.concurrent.PriorityBlockingQueue; @SuppressWarnings("unchecked") public class BiggernYours { @@ -152,7 +170,7 @@ static int randomize(int size) { return rnd.nextInt(size + 2); } @SuppressWarnings("serial") - private static void realMain(String[] args) throws Throwable { + private static void realMain(String[] args) { testNavigableMaps( new ConcurrentSkipListMap(), new ConcurrentSkipListMap() { @@ -232,7 +250,7 @@ static void arrayEqual(Object[] x, Object[] y) { if (x == null ? y == null : Arrays.equals(x, y)) pass(); else fail(Arrays.toString(x) + " not equal to " + Arrays.toString(y));} - public static void main(String[] args) throws Throwable { + public static void main(String[] args) { try {realMain(args);} catch (Throwable t) {unexpected(t);} System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); if (failed > 0) throw new AssertionError("Some tests failed");} diff --git a/test/jdk/java/util/Collection/HotPotatoes.java b/test/jdk/java/util/Collection/HotPotatoes.java --- a/test/jdk/java/util/Collection/HotPotatoes.java +++ b/test/jdk/java/util/Collection/HotPotatoes.java @@ -28,9 +28,16 @@ * @author Martin Buchholz */ -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.PriorityQueue; +import java.util.Vector; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.PriorityBlockingQueue; @SuppressWarnings("unchecked") public class HotPotatoes { diff --git a/test/jdk/java/util/Collection/IteratorAtEnd.java b/test/jdk/java/util/Collection/IteratorAtEnd.java --- a/test/jdk/java/util/Collection/IteratorAtEnd.java +++ b/test/jdk/java/util/Collection/IteratorAtEnd.java @@ -28,8 +28,34 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.PriorityQueue; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Vector; +import java.util.WeakHashMap; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.LinkedTransferQueue; @SuppressWarnings("unchecked") public class IteratorAtEnd { diff --git a/test/jdk/java/util/Collection/IteratorMicroBenchmark.java b/test/jdk/java/util/Collection/IteratorMicroBenchmark.java --- a/test/jdk/java/util/Collection/IteratorMicroBenchmark.java +++ b/test/jdk/java/util/Collection/IteratorMicroBenchmark.java @@ -28,10 +28,10 @@ */ import static java.util.stream.Collectors.summingInt; +import static java.util.stream.Collectors.toList; import java.lang.ref.WeakReference; import java.util.ArrayDeque; -import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -205,12 +205,10 @@ } private static List filter(Pattern filter, List jobs) { - if (filter == null) return jobs; - ArrayList newJobs = new ArrayList<>(); - for (Job job : jobs) - if (filter.matcher(job.name()).find()) - newJobs.add(job); - return newJobs; + return (filter == null) ? jobs + : jobs.stream() + .filter(job -> filter.matcher(job.name()).find()) + .collect(toList()); } private static void deoptimize(int sum) { @@ -270,9 +268,10 @@ abq.add(abq.remove()); } - ArrayList jobs = new ArrayList<>(Arrays.asList()); + ArrayList jobs = new ArrayList<>(); - List.of(al, ad, abq, + List.>of( + al, ad, abq, new LinkedList<>(al), new PriorityQueue<>(al), new Vector<>(al), @@ -281,9 +280,8 @@ new LinkedBlockingQueue<>(al), new LinkedBlockingDeque<>(al), new LinkedTransferQueue<>(al), - new PriorityBlockingQueue<>(al)) - .stream() - .forEach(x -> { + new PriorityBlockingQueue<>(al)).forEach( + x -> { jobs.addAll(collectionJobs(x)); if (x instanceof Deque) jobs.addAll(dequeJobs((Deque)x)); diff --git a/test/jdk/java/util/Collection/RemoveMicroBenchmark.java b/test/jdk/java/util/Collection/RemoveMicroBenchmark.java --- a/test/jdk/java/util/Collection/RemoveMicroBenchmark.java +++ b/test/jdk/java/util/Collection/RemoveMicroBenchmark.java @@ -27,6 +27,8 @@ * @run main RemoveMicroBenchmark iterations=1 size=8 warmup=0 */ +import static java.util.stream.Collectors.toList; + import java.lang.ref.WeakReference; import java.util.ArrayDeque; import java.util.ArrayList; @@ -202,12 +204,10 @@ } private static List filter(Pattern filter, List jobs) { - if (filter == null) return jobs; - ArrayList newJobs = new ArrayList<>(); - for (Job job : jobs) - if (filter.matcher(job.name()).find()) - newJobs.add(job); - return newJobs; + return (filter == null) ? jobs + : jobs.stream() + .filter(job -> filter.matcher(job.name()).find()) + .collect(toList()); } private static void deoptimize(int sum) { @@ -271,8 +271,7 @@ new LinkedBlockingQueue<>(), new LinkedBlockingDeque<>(), new LinkedTransferQueue<>(), - new PriorityBlockingQueue<>()) - .stream().forEach( + new PriorityBlockingQueue<>()).forEach( x -> { String klazz = x.getClass().getSimpleName(); jobs.addAll(collectionJobs(klazz, () -> x, al)); diff --git a/test/jdk/java/util/Collections/AddAll.java b/test/jdk/java/util/Collections/AddAll.java --- a/test/jdk/java/util/Collections/AddAll.java +++ b/test/jdk/java/util/Collections/AddAll.java @@ -29,7 +29,15 @@ * @key randomness */ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; public class AddAll { static final int N = 100; diff --git a/test/jdk/java/util/Collections/BigBinarySearch.java b/test/jdk/java/util/Collections/BigBinarySearch.java --- a/test/jdk/java/util/Collections/BigBinarySearch.java +++ b/test/jdk/java/util/Collections/BigBinarySearch.java @@ -28,7 +28,13 @@ * @author Martin Buchholz */ -import java.util.*; +import java.util.AbstractList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.RandomAccess; public class BigBinarySearch { diff --git a/test/jdk/java/util/Collections/BinarySearchNullComparator.java b/test/jdk/java/util/Collections/BinarySearchNullComparator.java --- a/test/jdk/java/util/Collections/BinarySearchNullComparator.java +++ b/test/jdk/java/util/Collections/BinarySearchNullComparator.java @@ -27,7 +27,9 @@ * @summary Test Collections.binarySearch() with a null comparator */ -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; public class BinarySearchNullComparator { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Collections/CheckedIdentityMap.java b/test/jdk/java/util/Collections/CheckedIdentityMap.java --- a/test/jdk/java/util/Collections/CheckedIdentityMap.java +++ b/test/jdk/java/util/Collections/CheckedIdentityMap.java @@ -28,14 +28,15 @@ * @summary Checked collections with underlying maps with identity comparisons */ -import java.util.*; -import static java.util.Collections.*; +import org.testng.annotations.Test; +import java.util.IdentityHashMap; +import java.util.Map; + +import static java.util.Collections.checkedMap; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotEquals; -import org.testng.annotations.Test; - public class CheckedIdentityMap { @Test diff --git a/test/jdk/java/util/Collections/CheckedListBash.java b/test/jdk/java/util/Collections/CheckedListBash.java --- a/test/jdk/java/util/Collections/CheckedListBash.java +++ b/test/jdk/java/util/Collections/CheckedListBash.java @@ -29,7 +29,13 @@ * @key randomness */ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Random; public class CheckedListBash { static Random rnd = new Random(); diff --git a/test/jdk/java/util/Collections/CheckedMapBash.java b/test/jdk/java/util/Collections/CheckedMapBash.java --- a/test/jdk/java/util/Collections/CheckedMapBash.java +++ b/test/jdk/java/util/Collections/CheckedMapBash.java @@ -30,10 +30,20 @@ * @key randomness */ -import java.util.*; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; import java.util.function.Supplier; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; import static org.testng.Assert.fail; diff --git a/test/jdk/java/util/Collections/CheckedNull.java b/test/jdk/java/util/Collections/CheckedNull.java --- a/test/jdk/java/util/Collections/CheckedNull.java +++ b/test/jdk/java/util/Collections/CheckedNull.java @@ -27,8 +27,18 @@ * @summary Test behavior of nulls in checked collections */ -import java.util.*; -import static java.util.Collections.*; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.TreeSet; + +import static java.util.Collections.singleton; +import static java.util.Collections.singletonMap; @SuppressWarnings({"unchecked","serial"}) public class CheckedNull { diff --git a/test/jdk/java/util/Collections/CheckedSetBash.java b/test/jdk/java/util/Collections/CheckedSetBash.java --- a/test/jdk/java/util/Collections/CheckedSetBash.java +++ b/test/jdk/java/util/Collections/CheckedSetBash.java @@ -30,13 +30,23 @@ * @key randomness */ -import java.util.*; -import java.util.function.Supplier; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.Supplier; + +import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; -import static org.testng.Assert.assertTrue; public class CheckedSetBash { static final int numItr = 100; diff --git a/test/jdk/java/util/Collections/Disjoint.java b/test/jdk/java/util/Collections/Disjoint.java --- a/test/jdk/java/util/Collections/Disjoint.java +++ b/test/jdk/java/util/Collections/Disjoint.java @@ -29,7 +29,11 @@ * @key randomness */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Random; public class Disjoint { static final int N = 20; diff --git a/test/jdk/java/util/Collections/EmptyCollectionSerialization.java b/test/jdk/java/util/Collections/EmptyCollectionSerialization.java --- a/test/jdk/java/util/Collections/EmptyCollectionSerialization.java +++ b/test/jdk/java/util/Collections/EmptyCollectionSerialization.java @@ -29,14 +29,22 @@ * @run testng EmptyCollectionSerialization */ -import java.util.*; -import java.util.function.Supplier; -import java.io.*; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.function.Supplier; + +import static org.testng.Assert.assertSame; import static org.testng.Assert.fail; -import static org.testng.Assert.assertSame; public class EmptyCollectionSerialization { private static Object patheticDeepCopy(Object o) throws Exception { diff --git a/test/jdk/java/util/Collections/EmptyIterator.java b/test/jdk/java/util/Collections/EmptyIterator.java --- a/test/jdk/java/util/Collections/EmptyIterator.java +++ b/test/jdk/java/util/Collections/EmptyIterator.java @@ -27,10 +27,25 @@ * @summary Test empty iterators, enumerations, and collections */ -import static java.util.Collections.*; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; import java.util.concurrent.SynchronousQueue; +import static java.util.Collections.emptyEnumeration; +import static java.util.Collections.emptyIterator; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyListIterator; +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; +import static java.util.Collections.nCopies; +import static java.util.Collections.unmodifiableMap; + public class EmptyIterator { void test(String[] args) throws Throwable { diff --git a/test/jdk/java/util/Collections/EmptyNavigableMap.java b/test/jdk/java/util/Collections/EmptyNavigableMap.java --- a/test/jdk/java/util/Collections/EmptyNavigableMap.java +++ b/test/jdk/java/util/Collections/EmptyNavigableMap.java @@ -27,6 +27,12 @@ * @summary Unit test for Collections.emptyNavigableMap * @run testng EmptyNavigableMap */ + +import org.testng.Assert; +import org.testng.Assert.ThrowingRunnable; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; @@ -37,13 +43,8 @@ import java.util.SortedMap; import java.util.TreeMap; -import org.testng.Assert; -import org.testng.Assert.ThrowingRunnable; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; - +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertFalse; public class EmptyNavigableMap { @@ -124,10 +125,9 @@ */ @Test(dataProvider = "NavigableMap", dataProviderClass = EmptyNavigableMap.class) public void testContainsRequiresComparable(String description, NavigableMap navigableMap) { - assertThrowsCCE(() -> { - navigableMap.containsKey(new Object()); - }, - description + ": Compareable should be required"); + assertThrowsCCE( + () -> navigableMap.containsKey(new Object()), + description + ": Comparable should be required"); } /** @@ -252,9 +252,7 @@ Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO; assertThrowsIAE( - () -> { - navigableMap.subMap(last, true, first, false); - }, + () -> navigableMap.subMap(last, true, first, false), description + ": Must throw IllegalArgumentException when fromElement is not less than toElement."); navigableMap.subMap(first, true, last, false); @@ -273,9 +271,8 @@ // slightly smaller NavigableMap ns = subMap.subMap(first, false, last, false); // slight expansion - assertThrowsIAE(() -> { - ns.subMap(first, true, last, true); - }, + assertThrowsIAE( + () -> ns.subMap(first, true, last, true), description + ": Expansion should not be allowed"); // much smaller @@ -293,9 +290,8 @@ NavigableMap ns = subMap.headMap(BigInteger.ONE, false); // slight expansion - assertThrowsIAE(() -> { - ns.headMap(BigInteger.ONE, true); - }, + assertThrowsIAE( + () -> ns.headMap(BigInteger.ONE, true), description + ": Expansion should not be allowed"); // much smaller @@ -313,9 +309,8 @@ NavigableMap ns = subMap.tailMap(BigInteger.ONE, false); // slight expansion - assertThrowsIAE(() -> { - ns.tailMap(BigInteger.ONE, true); - }, + assertThrowsIAE( + () -> ns.tailMap(BigInteger.ONE, true), description + ": Expansion should not be allowed"); // much smaller @@ -327,14 +322,12 @@ */ @Test(dataProvider = "NavigableMap", dataProviderClass = EmptyNavigableMap.class) public void testTailMap(String description, NavigableMap navigableMap) { - assertThrowsNPE(() -> { - navigableMap.tailMap(null); - }, + assertThrowsNPE( + () -> navigableMap.tailMap(null), description + ": Must throw NullPointerException for null element"); - assertThrowsCCE(() -> { - navigableMap.tailMap(new Object()); - }, + assertThrowsCCE( + () -> navigableMap.tailMap(new Object()), description); NavigableMap ss = navigableMap.tailMap("1", true); diff --git a/test/jdk/java/util/Collections/EmptyNavigableSet.java b/test/jdk/java/util/Collections/EmptyNavigableSet.java --- a/test/jdk/java/util/Collections/EmptyNavigableSet.java +++ b/test/jdk/java/util/Collections/EmptyNavigableSet.java @@ -27,22 +27,23 @@ * @summary Unit test for Collections.emptyNavigableSet * @run testng EmptyNavigableSet */ + +import org.testng.Assert; +import org.testng.Assert.ThrowingRunnable; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; +import java.util.NavigableSet; import java.util.NoSuchElementException; -import java.util.NavigableSet; import java.util.SortedSet; import java.util.TreeSet; -import org.testng.Assert; -import org.testng.Assert.ThrowingRunnable; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; - import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; @@ -130,10 +131,9 @@ */ @Test(dataProvider = "NavigableSet", dataProviderClass = EmptyNavigableSet.class) public void testContainsRequiresComparable(String description, NavigableSet navigableSet) { - assertThrowsCCE(() -> { - navigableSet.contains(new Object()); - }, - description + ": Compareable should be required"); + assertThrowsCCE( + () -> navigableSet.contains(new Object()), + description + ": Comparable should be required"); } /** @@ -182,9 +182,7 @@ */ @Test(dataProvider = "NavigableSet", dataProviderClass = EmptyNavigableSet.class) public void testFirst(String description, NavigableSet navigableSet) { - assertThrowsNSEE(() -> { - navigableSet.first(); - }, description); + assertThrowsNSEE(navigableSet::first, description); } /** @@ -210,9 +208,7 @@ */ @Test(dataProvider = "NavigableSet", dataProviderClass = EmptyNavigableSet.class) public void testLast(String description, NavigableSet navigableSet) { - assertThrowsNSEE(() -> { - navigableSet.last(); - }, description); + assertThrowsNSEE(navigableSet::last, description); } /** @@ -277,9 +273,7 @@ Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO; assertThrowsIAE( - () -> { - navigableSet.subSet(last, true, first, false); - }, + () -> navigableSet.subSet(last, true, first, false), description + ": Must throw IllegalArgumentException when fromElement is not less than toElement."); @@ -299,9 +293,8 @@ // slightly smaller NavigableSet ns = subSet.subSet(first, false, last, false); // slight expansion - assertThrowsIAE(() -> { - ns.subSet(first, true, last, true); - }, + assertThrowsIAE( + () -> ns.subSet(first, true, last, true), description + ": Expansion should not be allowed"); // much smaller @@ -319,9 +312,8 @@ NavigableSet ns = subSet.headSet(BigInteger.ONE, false); // slight expansion - assertThrowsIAE(() -> { - ns.headSet(BigInteger.ONE, true); - }, + assertThrowsIAE( + () -> ns.headSet(BigInteger.ONE, true), description + ": Expansion should not be allowed"); // much smaller @@ -339,9 +331,8 @@ NavigableSet ns = subSet.tailSet(BigInteger.ONE, false); // slight expansion - assertThrowsIAE(() -> { - ns.tailSet(BigInteger.ONE, true); - }, + assertThrowsIAE( + () -> ns.tailSet(BigInteger.ONE, true), description + ": Expansion should not be allowed"); // much smaller @@ -353,14 +344,13 @@ */ @Test(dataProvider = "NavigableSet", dataProviderClass = EmptyNavigableSet.class) public void testTailSet(String description, NavigableSet navigableSet) { - assertThrowsNPE(() -> { - navigableSet.tailSet(null); - }, + assertThrowsNPE( + () -> navigableSet.tailSet(null), description + ": Must throw NullPointerException for null element"); - assertThrowsCCE(() -> { - navigableSet.tailSet(new Object()); - }, description); + assertThrowsCCE( + () -> navigableSet.tailSet(new Object()), + description); NavigableSet ss = navigableSet.tailSet("1", true); diff --git a/test/jdk/java/util/Collections/Enum.java b/test/jdk/java/util/Collections/Enum.java --- a/test/jdk/java/util/Collections/Enum.java +++ b/test/jdk/java/util/Collections/Enum.java @@ -27,7 +27,9 @@ * @summary Basic test for new Enumeration -> List converter */ -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Vector; public class Enum { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Collections/FindSubList.java b/test/jdk/java/util/Collections/FindSubList.java --- a/test/jdk/java/util/Collections/FindSubList.java +++ b/test/jdk/java/util/Collections/FindSubList.java @@ -27,7 +27,12 @@ * @summary Basic test for Collections.indexOfSubList/lastIndexOfSubList */ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Vector; public class FindSubList { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Collections/Frequency.java b/test/jdk/java/util/Collections/Frequency.java --- a/test/jdk/java/util/Collections/Frequency.java +++ b/test/jdk/java/util/Collections/Frequency.java @@ -28,7 +28,10 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; public class Frequency { static final int N = 100; diff --git a/test/jdk/java/util/Collections/MinMax.java b/test/jdk/java/util/Collections/MinMax.java --- a/test/jdk/java/util/Collections/MinMax.java +++ b/test/jdk/java/util/Collections/MinMax.java @@ -29,7 +29,9 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; public class MinMax { public static void main(String[] args) { diff --git a/test/jdk/java/util/Collections/NCopies.java b/test/jdk/java/util/Collections/NCopies.java --- a/test/jdk/java/util/Collections/NCopies.java +++ b/test/jdk/java/util/Collections/NCopies.java @@ -28,8 +28,8 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.Collections; +import java.util.List; public class NCopies { static volatile int passed = 0, failed = 0; diff --git a/test/jdk/java/util/Collections/NullComparator.java b/test/jdk/java/util/Collections/NullComparator.java --- a/test/jdk/java/util/Collections/NullComparator.java +++ b/test/jdk/java/util/Collections/NullComparator.java @@ -27,7 +27,10 @@ * @summary A null Comparator is now specified to indicate natural ordering. */ -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; public class NullComparator { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Collections/RacingCollections.java b/test/jdk/java/util/Collections/RacingCollections.java --- a/test/jdk/java/util/Collections/RacingCollections.java +++ b/test/jdk/java/util/Collections/RacingCollections.java @@ -28,9 +28,46 @@ * @author Martin Buchholz */ -import static java.util.Collections.*; -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Deque; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Vector; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.LinkedTransferQueue; + +import static java.util.Collections.asLifoQueue; +import static java.util.Collections.checkedList; +import static java.util.Collections.checkedMap; +import static java.util.Collections.checkedSet; +import static java.util.Collections.newSetFromMap; +import static java.util.Collections.synchronizedList; +import static java.util.Collections.synchronizedMap; +import static java.util.Collections.synchronizedSet; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; +import static java.util.Collections.unmodifiableSet; public class RacingCollections { /** diff --git a/test/jdk/java/util/Collections/ReplaceAll.java b/test/jdk/java/util/Collections/ReplaceAll.java --- a/test/jdk/java/util/Collections/ReplaceAll.java +++ b/test/jdk/java/util/Collections/ReplaceAll.java @@ -27,7 +27,11 @@ * @summary Basic test for new replaceAll algorithm */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Vector; public class ReplaceAll { static final int SIZE = 20; diff --git a/test/jdk/java/util/Collections/ReverseOrder.java b/test/jdk/java/util/Collections/ReverseOrder.java --- a/test/jdk/java/util/Collections/ReverseOrder.java +++ b/test/jdk/java/util/Collections/ReverseOrder.java @@ -28,8 +28,14 @@ * @author Josh Bloch */ -import java.util.*; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; public class ReverseOrder { static byte[] serialBytes(Object o) { diff --git a/test/jdk/java/util/Collections/ReverseOrder2.java b/test/jdk/java/util/Collections/ReverseOrder2.java --- a/test/jdk/java/util/Collections/ReverseOrder2.java +++ b/test/jdk/java/util/Collections/ReverseOrder2.java @@ -28,8 +28,17 @@ * @author Josh Bloch, Martin Buchholz */ -import java.util.*; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; public class ReverseOrder2 { static final int N = 100; diff --git a/test/jdk/java/util/Collections/Rotate.java b/test/jdk/java/util/Collections/Rotate.java --- a/test/jdk/java/util/Collections/Rotate.java +++ b/test/jdk/java/util/Collections/Rotate.java @@ -28,7 +28,12 @@ * @key randomness */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Vector; public class Rotate { // Should have lots of distinct factors and be > ROTATE_THRESHOLD diff --git a/test/jdk/java/util/Collections/RotateEmpty.java b/test/jdk/java/util/Collections/RotateEmpty.java --- a/test/jdk/java/util/Collections/RotateEmpty.java +++ b/test/jdk/java/util/Collections/RotateEmpty.java @@ -27,7 +27,9 @@ * @summary Collections.rotate(...) returns ArithmeticException */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class RotateEmpty { diff --git a/test/jdk/java/util/Collections/Ser.java b/test/jdk/java/util/Collections/Ser.java --- a/test/jdk/java/util/Collections/Ser.java +++ b/test/jdk/java/util/Collections/Ser.java @@ -28,8 +28,13 @@ * nCopies and singleton were spec'd to be serializable, but weren't. */ -import java.io.*; -import java.util.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Collections; +import java.util.List; +import java.util.Set; public class Ser { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Collections/SetFromMap.java b/test/jdk/java/util/Collections/SetFromMap.java --- a/test/jdk/java/util/Collections/SetFromMap.java +++ b/test/jdk/java/util/Collections/SetFromMap.java @@ -28,7 +28,10 @@ * @author Martin Buchholz */ -import java.util.*; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; public class SetFromMap { static volatile int passed = 0, failed = 0; diff --git a/test/jdk/java/util/Collections/Swap.java b/test/jdk/java/util/Collections/Swap.java --- a/test/jdk/java/util/Collections/Swap.java +++ b/test/jdk/java/util/Collections/Swap.java @@ -28,7 +28,9 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; public class Swap { static final int SIZE = 100; diff --git a/test/jdk/java/util/Collections/T5078378.java b/test/jdk/java/util/Collections/T5078378.java --- a/test/jdk/java/util/Collections/T5078378.java +++ b/test/jdk/java/util/Collections/T5078378.java @@ -21,7 +21,7 @@ * questions. */ -/** +/* * @test * @bug 5078378 * @summary REGRESSION: Some calls to Collections.binarySearch no longer compile @@ -30,7 +30,9 @@ * @compile T5078378.java * @compile/fail -Xlint:unchecked -Werror T5078378.java */ -import java.util.*; + +import java.util.Collections; +import java.util.List; class T5078378 { public static boolean contains(List l, Object o) { diff --git a/test/jdk/java/util/Collections/T6433170.java b/test/jdk/java/util/Collections/T6433170.java --- a/test/jdk/java/util/Collections/T6433170.java +++ b/test/jdk/java/util/Collections/T6433170.java @@ -27,8 +27,16 @@ * @summary CheckedCollection.addAll should be all-or-nothing */ -import java.util.*; -import static java.util.Collections.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Vector; + +import static java.util.Collections.checkedCollection; +import static java.util.Collections.checkedList; +import static java.util.Collections.checkedSet; @SuppressWarnings("unchecked") public class T6433170 { diff --git a/test/jdk/java/util/Collections/ViewSynch.java b/test/jdk/java/util/Collections/ViewSynch.java --- a/test/jdk/java/util/Collections/ViewSynch.java +++ b/test/jdk/java/util/Collections/ViewSynch.java @@ -29,7 +29,11 @@ * (Got that?) */ -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; public class ViewSynch { static final Integer ZERO = new Integer(0); diff --git a/test/jdk/java/util/Collections/WrappedNull.java b/test/jdk/java/util/Collections/WrappedNull.java --- a/test/jdk/java/util/Collections/WrappedNull.java +++ b/test/jdk/java/util/Collections/WrappedNull.java @@ -28,7 +28,16 @@ * rather than later */ -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; public class WrappedNull { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/HashMap/KeySetRemove.java b/test/jdk/java/util/HashMap/KeySetRemove.java --- a/test/jdk/java/util/HashMap/KeySetRemove.java +++ b/test/jdk/java/util/HashMap/KeySetRemove.java @@ -28,7 +28,9 @@ * false if the Map previously mapped k to null. */ -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; public class KeySetRemove { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/HashMap/SetValue.java b/test/jdk/java/util/HashMap/SetValue.java --- a/test/jdk/java/util/HashMap/SetValue.java +++ b/test/jdk/java/util/HashMap/SetValue.java @@ -28,7 +28,8 @@ * @author jbloch */ -import java.util.*; +import java.util.HashMap; +import java.util.Map; public class SetValue { static final String key = "key"; diff --git a/test/jdk/java/util/HashMap/ToString.java b/test/jdk/java/util/HashMap/ToString.java --- a/test/jdk/java/util/HashMap/ToString.java +++ b/test/jdk/java/util/HashMap/ToString.java @@ -28,7 +28,8 @@ * contained null keys or values. */ -import java.util.*; +import java.util.HashMap; +import java.util.Map; public class ToString { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Hashtable/EqualsCast.java b/test/jdk/java/util/Hashtable/EqualsCast.java --- a/test/jdk/java/util/Hashtable/EqualsCast.java +++ b/test/jdk/java/util/Hashtable/EqualsCast.java @@ -29,8 +29,8 @@ * unnecessarily. (java.security.Provider tickled this sensitivity.) */ -import java.util.*; import java.security.Provider; +import java.util.Map; public class EqualsCast { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Hashtable/HashCode.java b/test/jdk/java/util/Hashtable/HashCode.java --- a/test/jdk/java/util/Hashtable/HashCode.java +++ b/test/jdk/java/util/Hashtable/HashCode.java @@ -28,7 +28,8 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.Hashtable; +import java.util.Map; public class HashCode { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Hashtable/IllegalLoadFactor.java b/test/jdk/java/util/Hashtable/IllegalLoadFactor.java --- a/test/jdk/java/util/Hashtable/IllegalLoadFactor.java +++ b/test/jdk/java/util/Hashtable/IllegalLoadFactor.java @@ -26,7 +26,12 @@ @summary Test for an illegalargumentexception on loadFactor */ -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; +import java.util.WeakHashMap; /** * This class tests to see if creating a hash table with an diff --git a/test/jdk/java/util/Hashtable/ReadObject.java b/test/jdk/java/util/Hashtable/ReadObject.java --- a/test/jdk/java/util/Hashtable/ReadObject.java +++ b/test/jdk/java/util/Hashtable/ReadObject.java @@ -21,18 +21,18 @@ * questions. */ -/** +/* * @test * @bug 4652911 * @summary test Hashtable readObject for invocation of overridable put method */ -import java.util.Hashtable; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ObjectInputStream; import java.io.Serializable; +import java.util.Hashtable; /** * Class that extends Hashtable to demonstrate bug when @@ -52,7 +52,7 @@ Object getValue() { return mValue; } - }; + } public Object get(Object key) { ValueWrapper valueWrapper = (ValueWrapper)super.get(key); diff --git a/test/jdk/java/util/Hashtable/SelfRef.java b/test/jdk/java/util/Hashtable/SelfRef.java --- a/test/jdk/java/util/Hashtable/SelfRef.java +++ b/test/jdk/java/util/Hashtable/SelfRef.java @@ -29,8 +29,11 @@ * @author Josh Bloch, Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class SelfRef { public static void main(String[] args) { diff --git a/test/jdk/java/util/IdentityHashMap/ToArray.java b/test/jdk/java/util/IdentityHashMap/ToArray.java --- a/test/jdk/java/util/IdentityHashMap/ToArray.java +++ b/test/jdk/java/util/IdentityHashMap/ToArray.java @@ -28,7 +28,11 @@ * @author Josh Bloch, Martin Buchholz */ -import java.util.*; +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; public class ToArray { public static void main(String[] args) { diff --git a/test/jdk/java/util/IdentityHashMap/ToString.java b/test/jdk/java/util/IdentityHashMap/ToString.java --- a/test/jdk/java/util/IdentityHashMap/ToString.java +++ b/test/jdk/java/util/IdentityHashMap/ToString.java @@ -28,7 +28,10 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; public class ToString { public static void main(String[] args) { diff --git a/test/jdk/java/util/LinkedHashMap/Basic.java b/test/jdk/java/util/LinkedHashMap/Basic.java --- a/test/jdk/java/util/LinkedHashMap/Basic.java +++ b/test/jdk/java/util/LinkedHashMap/Basic.java @@ -27,9 +27,21 @@ * @summary Basic test for LinkedHashMap. (Based on MapBash) */ -import java.util.*; -import java.util.function.*; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Random; +import java.util.Set; +import java.util.function.BiFunction; public class Basic { static final Random rnd = new Random(666); diff --git a/test/jdk/java/util/LinkedHashMap/Cache.java b/test/jdk/java/util/LinkedHashMap/Cache.java --- a/test/jdk/java/util/LinkedHashMap/Cache.java +++ b/test/jdk/java/util/LinkedHashMap/Cache.java @@ -27,7 +27,8 @@ * @summary Basic test of removeEldestElement method. */ -import java.util.*; +import java.util.LinkedHashMap; +import java.util.Map; public class Cache { private static final int MAP_SIZE = 10; diff --git a/test/jdk/java/util/LinkedHashMap/EmptyMapIterator.java b/test/jdk/java/util/LinkedHashMap/EmptyMapIterator.java --- a/test/jdk/java/util/LinkedHashMap/EmptyMapIterator.java +++ b/test/jdk/java/util/LinkedHashMap/EmptyMapIterator.java @@ -27,12 +27,14 @@ * @summary iterators on collection views of empty map weren't fail-fast. */ -import java.util.*; +import java.util.ConcurrentModificationException; +import java.util.HashMap; +import java.util.Iterator; public class EmptyMapIterator { public static void main(String[] args) throws Exception { HashMap map = new HashMap(); - Iterator iter = iter = map.entrySet().iterator(); + Iterator iter = map.entrySet().iterator(); map.put("key", "value"); try { diff --git a/test/jdk/java/util/LinkedHashSet/Basic.java b/test/jdk/java/util/LinkedHashSet/Basic.java --- a/test/jdk/java/util/LinkedHashSet/Basic.java +++ b/test/jdk/java/util/LinkedHashSet/Basic.java @@ -27,8 +27,15 @@ * @summary Basic test for LinkedHashSet. (Based on SetBash) */ -import java.util.*; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Random; +import java.util.Set; public class Basic { static Random rnd = new Random(666); diff --git a/test/jdk/java/util/LinkedList/AddAll.java b/test/jdk/java/util/LinkedList/AddAll.java --- a/test/jdk/java/util/LinkedList/AddAll.java +++ b/test/jdk/java/util/LinkedList/AddAll.java @@ -27,7 +27,10 @@ * @summary AddAll was prepending instead of appending! */ -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; public class AddAll { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/LinkedList/Clone.java b/test/jdk/java/util/LinkedList/Clone.java --- a/test/jdk/java/util/LinkedList/Clone.java +++ b/test/jdk/java/util/LinkedList/Clone.java @@ -29,7 +29,9 @@ * TreeMap. */ -import java.util.*; +import java.util.LinkedList; +import java.util.TreeMap; +import java.util.TreeSet; public class Clone { public static void main(String[] args) { diff --git a/test/jdk/java/util/LinkedList/ComodifiedRemove.java b/test/jdk/java/util/LinkedList/ComodifiedRemove.java --- a/test/jdk/java/util/LinkedList/ComodifiedRemove.java +++ b/test/jdk/java/util/LinkedList/ComodifiedRemove.java @@ -29,9 +29,10 @@ * @author Konstantin Kladko */ -import java.util.*; +import java.util.ConcurrentModificationException; +import java.util.LinkedList; +import java.util.List; import java.util.ListIterator; -import java.util.ConcurrentModificationException; public class ComodifiedRemove { public static diff --git a/test/jdk/java/util/List/LockStep.java b/test/jdk/java/util/List/LockStep.java --- a/test/jdk/java/util/List/LockStep.java +++ b/test/jdk/java/util/List/LockStep.java @@ -29,10 +29,23 @@ * @key randomness */ -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import static java.util.Collections.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; +import java.util.Random; +import java.util.Vector; @SuppressWarnings("unchecked") public class LockStep { diff --git a/test/jdk/java/util/Map/Defaults.java b/test/jdk/java/util/Map/Defaults.java --- a/test/jdk/java/util/Map/Defaults.java +++ b/test/jdk/java/util/Map/Defaults.java @@ -28,6 +28,11 @@ * @author Mike Duigou * @run testng Defaults */ + +import org.testng.Assert.ThrowingRunnable; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + import java.util.AbstractMap; import java.util.AbstractSet; import java.util.ArrayList; @@ -36,36 +41,31 @@ import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; -import java.util.HashSet; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import java.util.TreeMap; import java.util.Set; +import java.util.TreeMap; import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; -import org.testng.Assert.ThrowingRunnable; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; - import static java.util.Objects.requireNonNull; - -import static org.testng.Assert.fail; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertThrows; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; public class Defaults { @@ -730,7 +730,7 @@ e90, e91, e92, e93, e94, e95, e96, e97, e98, e99, EXTRA_KEY; public static final int SIZE = values().length; - }; + } private static final int TEST_SIZE = IntegerEnum.SIZE - 1; /** * Realized keys ensure that there is always a hard ref to all test objects. diff --git a/test/jdk/java/util/Map/Get.java b/test/jdk/java/util/Map/Get.java --- a/test/jdk/java/util/Map/Get.java +++ b/test/jdk/java/util/Map/Get.java @@ -28,10 +28,18 @@ * @author Martin Buchholz */ -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentSkipListMap; public class Get { diff --git a/test/jdk/java/util/Map/LockStep.java b/test/jdk/java/util/Map/LockStep.java --- a/test/jdk/java/util/Map/LockStep.java +++ b/test/jdk/java/util/Map/LockStep.java @@ -28,8 +28,20 @@ * @key randomness */ -import java.util.*; -import java.util.concurrent.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.TreeMap; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; /** * Based on the strange scenario required to reproduce diff --git a/test/jdk/java/util/NavigableMap/LockStep.java b/test/jdk/java/util/NavigableMap/LockStep.java --- a/test/jdk/java/util/NavigableMap/LockStep.java +++ b/test/jdk/java/util/NavigableMap/LockStep.java @@ -32,10 +32,35 @@ * @key randomness */ -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import static java.util.Collections.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.NotSerializableException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.NoSuchElementException; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ConcurrentSkipListSet; + +import static java.util.Collections.reverseOrder; +import static java.util.Collections.singleton; +import static java.util.Collections.singletonMap; @SuppressWarnings("unchecked") public class LockStep { diff --git a/test/jdk/java/util/PriorityQueue/AddNonComparable.java b/test/jdk/java/util/PriorityQueue/AddNonComparable.java --- a/test/jdk/java/util/PriorityQueue/AddNonComparable.java +++ b/test/jdk/java/util/PriorityQueue/AddNonComparable.java @@ -27,6 +27,8 @@ * @run testng AddNonComparable */ +import org.testng.annotations.Test; + import java.util.PriorityQueue; import java.util.Queue; import java.util.SortedMap; @@ -39,8 +41,8 @@ import java.util.function.BiConsumer; import java.util.function.Supplier; -import static org.testng.Assert.*; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; public class AddNonComparable { diff --git a/test/jdk/java/util/PriorityQueue/NoNulls.java b/test/jdk/java/util/PriorityQueue/NoNulls.java --- a/test/jdk/java/util/PriorityQueue/NoNulls.java +++ b/test/jdk/java/util/PriorityQueue/NoNulls.java @@ -38,8 +38,8 @@ */ import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; -import java.util.Collection; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.TreeSet; diff --git a/test/jdk/java/util/PriorityQueue/PriorityQueueSort.java b/test/jdk/java/util/PriorityQueue/PriorityQueueSort.java --- a/test/jdk/java/util/PriorityQueue/PriorityQueueSort.java +++ b/test/jdk/java/util/PriorityQueue/PriorityQueueSort.java @@ -42,18 +42,14 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; +import java.util.PriorityQueue; import java.util.Queue; -import java.util.PriorityQueue; public class PriorityQueueSort { static class MyComparator implements Comparator { public int compare(Integer x, Integer y) { - int i = x.intValue(); - int j = y.intValue(); - if (i < j) return -1; - if (i > j) return 1; - return 0; + return Integer.compare(x.intValue(), y.intValue()); } } diff --git a/test/jdk/java/util/PriorityQueue/RemoveContains.java b/test/jdk/java/util/PriorityQueue/RemoveContains.java --- a/test/jdk/java/util/PriorityQueue/RemoveContains.java +++ b/test/jdk/java/util/PriorityQueue/RemoveContains.java @@ -37,8 +37,8 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.PriorityBlockingQueue; -import java.util.concurrent.LinkedTransferQueue; public class RemoveContains { static volatile int passed = 0, failed = 0; diff --git a/test/jdk/java/util/Random/NextBytes.java b/test/jdk/java/util/Random/NextBytes.java --- a/test/jdk/java/util/Random/NextBytes.java +++ b/test/jdk/java/util/Random/NextBytes.java @@ -28,7 +28,8 @@ * @author Martin Buchholz */ -import java.util.*; +import java.util.Arrays; +import java.util.Random; public class NextBytes { private static void realMain(String[] args) throws Throwable { diff --git a/test/jdk/java/util/TimSort/SortPerf.java b/test/jdk/java/util/TimSort/SortPerf.java --- a/test/jdk/java/util/TimSort/SortPerf.java +++ b/test/jdk/java/util/TimSort/SortPerf.java @@ -21,8 +21,6 @@ * questions. */ -import java.util.Arrays; - public class SortPerf { private static final int NUM_SETS = 5; private static final int[] lengths = { 10, 100, 1000, 10000, 1000000 }; diff --git a/test/jdk/java/util/TreeMap/ContainsValue.java b/test/jdk/java/util/TreeMap/ContainsValue.java --- a/test/jdk/java/util/TreeMap/ContainsValue.java +++ b/test/jdk/java/util/TreeMap/ContainsValue.java @@ -27,7 +27,8 @@ * @summary TreeMap.containsValue throws NullPointerExc for empty TreeMap */ -import java.util.*; +import java.util.Map; +import java.util.TreeMap; public class ContainsValue { public static void main(String[] args) { diff --git a/test/jdk/java/util/TreeMap/HeadTailTypeError.java b/test/jdk/java/util/TreeMap/HeadTailTypeError.java --- a/test/jdk/java/util/TreeMap/HeadTailTypeError.java +++ b/test/jdk/java/util/TreeMap/HeadTailTypeError.java @@ -28,7 +28,10 @@ * valid range in the backing array */ -import java.util.*; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; public class HeadTailTypeError { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/TreeMap/NullAtEnd.java b/test/jdk/java/util/TreeMap/NullAtEnd.java --- a/test/jdk/java/util/TreeMap/NullAtEnd.java +++ b/test/jdk/java/util/TreeMap/NullAtEnd.java @@ -28,8 +28,9 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; +import java.util.Comparator; +import java.util.SortedMap; +import java.util.TreeMap; public class NullAtEnd { static volatile int passed = 0, failed = 0; diff --git a/test/jdk/java/util/TreeMap/NullPermissiveComparator.java b/test/jdk/java/util/TreeMap/NullPermissiveComparator.java --- a/test/jdk/java/util/TreeMap/NullPermissiveComparator.java +++ b/test/jdk/java/util/TreeMap/NullPermissiveComparator.java @@ -28,10 +28,9 @@ * @author Martin Buchholz */ -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import java.lang.reflect.*; +import java.util.Comparator; +import java.util.Map; +import java.util.TreeMap; @SuppressWarnings("unchecked") public class NullPermissiveComparator { diff --git a/test/jdk/java/util/TreeMap/SubMap.java b/test/jdk/java/util/TreeMap/SubMap.java --- a/test/jdk/java/util/TreeMap/SubMap.java +++ b/test/jdk/java/util/TreeMap/SubMap.java @@ -27,7 +27,11 @@ * @summary The firstKey and lastKey */ -import java.util.*; +import java.util.NoSuchElementException; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; public class SubMap { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/TreeMap/SubMapClear.java b/test/jdk/java/util/TreeMap/SubMapClear.java --- a/test/jdk/java/util/TreeMap/SubMapClear.java +++ b/test/jdk/java/util/TreeMap/SubMapClear.java @@ -29,7 +29,9 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; public class SubMapClear { public static void main(String[] args) { diff --git a/test/jdk/java/util/Vector/ComodifiedRemoveAllElements.java b/test/jdk/java/util/Vector/ComodifiedRemoveAllElements.java --- a/test/jdk/java/util/Vector/ComodifiedRemoveAllElements.java +++ b/test/jdk/java/util/Vector/ComodifiedRemoveAllElements.java @@ -29,7 +29,9 @@ * @author Konstantin Kladko */ -import java.util.*; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.Vector; public class ComodifiedRemoveAllElements { public static void main(String[] args) { diff --git a/test/jdk/java/util/Vector/CopyInto.java b/test/jdk/java/util/Vector/CopyInto.java --- a/test/jdk/java/util/Vector/CopyInto.java +++ b/test/jdk/java/util/Vector/CopyInto.java @@ -28,10 +28,7 @@ * @author Martin Buchholz */ -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.Vector; public class CopyInto { private static void realMain(String[] args) throws Throwable { diff --git a/test/jdk/java/util/Vector/IllegalConstructorArgs.java b/test/jdk/java/util/Vector/IllegalConstructorArgs.java --- a/test/jdk/java/util/Vector/IllegalConstructorArgs.java +++ b/test/jdk/java/util/Vector/IllegalConstructorArgs.java @@ -27,7 +27,7 @@ * @summary Test for illegal argument exception */ -import java.util.*; +import java.util.Vector; /** * This is a simple test class created to check for diff --git a/test/jdk/java/util/Vector/LastIndexOf.java b/test/jdk/java/util/Vector/LastIndexOf.java --- a/test/jdk/java/util/Vector/LastIndexOf.java +++ b/test/jdk/java/util/Vector/LastIndexOf.java @@ -28,7 +28,7 @@ * valid range in the backing array */ -import java.util.*; +import java.util.Vector; public class LastIndexOf { public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/Vector/SyncLastIndexOf.java b/test/jdk/java/util/Vector/SyncLastIndexOf.java --- a/test/jdk/java/util/Vector/SyncLastIndexOf.java +++ b/test/jdk/java/util/Vector/SyncLastIndexOf.java @@ -27,7 +27,8 @@ * @summary Vector's lastIndexOf(Object) was lacking synchronization * @author Konstantin Kladko */ -import java.util.*; + +import java.util.Vector; public class SyncLastIndexOf { diff --git a/test/jdk/java/util/WeakHashMap/GCDuringIteration.java b/test/jdk/java/util/WeakHashMap/GCDuringIteration.java --- a/test/jdk/java/util/WeakHashMap/GCDuringIteration.java +++ b/test/jdk/java/util/WeakHashMap/GCDuringIteration.java @@ -32,7 +32,7 @@ * @key randomness */ -import static java.util.concurrent.TimeUnit.SECONDS; +import jdk.test.lib.RandomFactory; import java.lang.ref.WeakReference; import java.util.Arrays; @@ -43,7 +43,8 @@ import java.util.WeakHashMap; import java.util.concurrent.CountDownLatch; import java.util.function.BooleanSupplier; -import jdk.test.lib.RandomFactory; + +import static java.util.concurrent.TimeUnit.SECONDS; public class GCDuringIteration { diff --git a/test/jdk/java/util/WeakHashMap/Iteration.java b/test/jdk/java/util/WeakHashMap/Iteration.java --- a/test/jdk/java/util/WeakHashMap/Iteration.java +++ b/test/jdk/java/util/WeakHashMap/Iteration.java @@ -28,7 +28,9 @@ * @author Josh Bloch */ -import java.util.*; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; public class Iteration { public static void main(String[] args) { diff --git a/test/jdk/java/util/WeakHashMap/ZeroInitCap.java b/test/jdk/java/util/WeakHashMap/ZeroInitCap.java --- a/test/jdk/java/util/WeakHashMap/ZeroInitCap.java +++ b/test/jdk/java/util/WeakHashMap/ZeroInitCap.java @@ -21,7 +21,8 @@ * questions. */ -import java.util.*; +import java.util.Map; +import java.util.WeakHashMap; /* * @test diff --git a/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java b/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java --- a/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java +++ b/test/jdk/java/util/concurrent/ArrayBlockingQueue/WhiteBox.java @@ -39,7 +39,7 @@ */ import static org.testng.Assert.*; -import org.testng.annotations.DataProvider; + import org.testng.annotations.Test; import java.lang.ref.WeakReference; diff --git a/test/jdk/java/util/concurrent/BlockingQueue/DrainToFails.java b/test/jdk/java/util/concurrent/BlockingQueue/DrainToFails.java --- a/test/jdk/java/util/concurrent/BlockingQueue/DrainToFails.java +++ b/test/jdk/java/util/concurrent/BlockingQueue/DrainToFails.java @@ -78,9 +78,7 @@ pseudodelay = i; } public int compareTo(PDelay other) { - int a = this.pseudodelay; - int b = other.pseudodelay; - return (a < b) ? -1 : (a > b) ? 1 : 0; + return Integer.compare(this.pseudodelay, other.pseudodelay); } public int compareTo(Delayed y) { return compareTo((PDelay)y); diff --git a/test/jdk/java/util/concurrent/BlockingQueue/LoopHelpers.java b/test/jdk/java/util/concurrent/BlockingQueue/LoopHelpers.java --- a/test/jdk/java/util/concurrent/BlockingQueue/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/BlockingQueue/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/BlockingQueue/OfferDrainToLoops.java b/test/jdk/java/util/concurrent/BlockingQueue/OfferDrainToLoops.java --- a/test/jdk/java/util/concurrent/BlockingQueue/OfferDrainToLoops.java +++ b/test/jdk/java/util/concurrent/BlockingQueue/OfferDrainToLoops.java @@ -79,7 +79,7 @@ final long timeoutMillis = 10L * 1000L; final SplittableRandom rnd = new SplittableRandom(); - /** Poor man's bounded buffer. */ + // Poor man's bounded buffer. final AtomicLong approximateCount = new AtomicLong(0L); abstract class CheckedThread extends Thread { diff --git a/test/jdk/java/util/concurrent/CompletableFuture/Basic.java b/test/jdk/java/util/concurrent/CompletableFuture/Basic.java --- a/test/jdk/java/util/concurrent/CompletableFuture/Basic.java +++ b/test/jdk/java/util/concurrent/CompletableFuture/Basic.java @@ -200,32 +200,32 @@ try { CompletableFuture cf2; CompletableFuture cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenApply((x) -> { if (x.equals("a test string")) return 1; else return 0; }); - checkCompletedNormally(cf1, "a test string"); - checkCompletedNormally(cf2, 1); - - cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenApplyAsync((x) -> { if (x.equals("a test string")) return 1; else return 0; }); + cf2 = cf1.thenApply(x -> x.equals("a test string") ? 1 : 0); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, 1); cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenApplyAsync((x) -> { if (x.equals("a test string")) return 1; else return 0; }, executor); + cf2 = cf1.thenApplyAsync(x -> x.equals("a test string") ? 1 : 0); + checkCompletedNormally(cf1, "a test string"); + checkCompletedNormally(cf2, 1); + + cf1 = supplyAsync(() -> "a test string"); + cf2 = cf1.thenApplyAsync(x -> x.equals("a test string") ? 1 : 0, executor); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, 1); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenApply((x) -> { return 0; } ); + cf2 = cf1.thenApply(x -> 0); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenApplyAsync((x) -> { return 0; } ); + cf2 = cf1.thenApplyAsync(x -> 0); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenApplyAsync((x) -> { return 0; }, executor); + cf2 = cf1.thenApplyAsync(x -> 0, executor); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); } catch (Throwable t) { unexpected(t); } @@ -237,40 +237,40 @@ CompletableFuture cf2; int before = atomicInt.get(); CompletableFuture cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenAccept((x) -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }); - checkCompletedNormally(cf1, "a test string"); - checkCompletedNormally(cf2, null); - check(atomicInt.get() == (before + 1)); - - before = atomicInt.get(); - cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenAcceptAsync((x) -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }); + cf2 = cf1.thenAccept(x -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, null); check(atomicInt.get() == (before + 1)); before = atomicInt.get(); cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenAcceptAsync((x) -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }, executor); + cf2 = cf1.thenAcceptAsync(x -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }); + checkCompletedNormally(cf1, "a test string"); + checkCompletedNormally(cf2, null); + check(atomicInt.get() == (before + 1)); + + before = atomicInt.get(); + cf1 = supplyAsync(() -> "a test string"); + cf2 = cf1.thenAcceptAsync(x -> { if (x.equals("a test string")) { atomicInt.incrementAndGet(); return; } throw new RuntimeException(); }, executor); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, null); check(atomicInt.get() == (before + 1)); before = atomicInt.get(); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenAccept((x) -> { atomicInt.incrementAndGet(); } ); + cf2 = cf1.thenAccept(x -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenAcceptAsync((x) -> { atomicInt.incrementAndGet(); } ); + cf2 = cf1.thenAcceptAsync(x -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenAcceptAsync((x) -> { atomicInt.incrementAndGet(); }, executor ); + cf2 = cf1.thenAcceptAsync(x -> atomicInt.incrementAndGet(), executor ); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); @@ -283,40 +283,40 @@ CompletableFuture cf2; int before = atomicInt.get(); CompletableFuture cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenRun(() -> { atomicInt.incrementAndGet(); }); - checkCompletedNormally(cf1, "a test string"); - checkCompletedNormally(cf2, null); - check(atomicInt.get() == (before + 1)); - - before = atomicInt.get(); - cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenRunAsync(() -> { atomicInt.incrementAndGet(); }); + cf2 = cf1.thenRun(() -> atomicInt.incrementAndGet()); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, null); check(atomicInt.get() == (before + 1)); before = atomicInt.get(); cf1 = supplyAsync(() -> "a test string"); - cf2 = cf1.thenRunAsync(() -> { atomicInt.incrementAndGet(); }, executor); + cf2 = cf1.thenRunAsync(() -> atomicInt.incrementAndGet()); + checkCompletedNormally(cf1, "a test string"); + checkCompletedNormally(cf2, null); + check(atomicInt.get() == (before + 1)); + + before = atomicInt.get(); + cf1 = supplyAsync(() -> "a test string"); + cf2 = cf1.thenRunAsync(() -> atomicInt.incrementAndGet(), executor); checkCompletedNormally(cf1, "a test string"); checkCompletedNormally(cf2, null); check(atomicInt.get() == (before + 1)); before = atomicInt.get(); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenRun(() -> { atomicInt.incrementAndGet(); }); + cf2 = cf1.thenRun(() -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenRunAsync(() -> { atomicInt.incrementAndGet(); }); + cf2 = cf1.thenRunAsync(() -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenRunAsync(() -> { atomicInt.incrementAndGet(); }, executor); + cf2 = cf1.thenRunAsync(() -> atomicInt.incrementAndGet(), executor); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); @@ -329,42 +329,42 @@ CompletableFuture cf3; CompletableFuture cf1 = supplyAsync(() -> 1); CompletableFuture cf2 = supplyAsync(() -> 1); - cf3 = cf1.thenCombine(cf2, (x, y) -> { return x + y; }); - checkCompletedNormally(cf1, 1); - checkCompletedNormally(cf2, 1); - checkCompletedNormally(cf3, 2); - - cf1 = supplyAsync(() -> 1); - cf2 = supplyAsync(() -> 1); - cf3 = cf1.thenCombineAsync(cf2, (x, y) -> { return x + y; }); + cf3 = cf1.thenCombine(cf2, (x, y) -> x + y); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 1); checkCompletedNormally(cf3, 2); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> 1); - cf3 = cf1.thenCombineAsync(cf2, (x, y) -> { return x + y; }, executor); + cf3 = cf1.thenCombineAsync(cf2, (x, y) -> x + y); + checkCompletedNormally(cf1, 1); + checkCompletedNormally(cf2, 1); + checkCompletedNormally(cf3, 2); + + cf1 = supplyAsync(() -> 1); + cf2 = supplyAsync(() -> 1); + cf3 = cf1.thenCombineAsync(cf2, (x, y) -> x + y, executor); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 1); checkCompletedNormally(cf3, 2); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> 1); - cf3 = cf1.thenCombine(cf2, (x, y) -> { return 0; }); + cf3 = cf1.thenCombine(cf2, (x, y) -> 0); checkCompletedExceptionally(cf1); checkCompletedNormally(cf2, 1); checkCompletedExceptionally(cf3); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.thenCombineAsync(cf2, (x, y) -> { return 0; }); + cf3 = cf1.thenCombineAsync(cf2, (x, y) -> 0); checkCompletedNormally(cf1, 1); checkCompletedExceptionally(cf2); checkCompletedExceptionally(cf3); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.thenCombineAsync(cf2, (x, y) -> { return 0; }, executor); + cf3 = cf1.thenCombineAsync(cf2, (x, y) -> 0, executor); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); checkCompletedExceptionally(cf3); @@ -405,7 +405,7 @@ before = atomicInt.get(); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> 1); - cf3 = cf1.thenAcceptBoth(cf2, (x, y) -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.thenAcceptBoth(cf2, (x, y) -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf1); checkCompletedNormally(cf2, 1); checkCompletedExceptionally(cf3); @@ -413,7 +413,7 @@ cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.thenAcceptBothAsync(cf2, (x, y) -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.thenAcceptBothAsync(cf2, (x, y) -> atomicInt.incrementAndGet()); checkCompletedNormally(cf1, 1); checkCompletedExceptionally(cf2); checkCompletedExceptionally(cf3); @@ -421,7 +421,7 @@ cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.thenAcceptBothAsync(cf2, (x, y) -> { atomicInt.incrementAndGet(); }, executor); + cf3 = cf1.thenAcceptBothAsync(cf2, (x, y) -> atomicInt.incrementAndGet(), executor); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); checkCompletedExceptionally(cf3); @@ -463,7 +463,7 @@ before = atomicInt.get(); CompletableFuture cf4 = supplyAsync(() -> { throw new RuntimeException(); }); CompletableFuture cf5 = supplyAsync(() -> 1); - cf3 = cf5.runAfterBothAsync(cf4, () -> { atomicInt.incrementAndGet(); }, executor); + cf3 = cf5.runAfterBothAsync(cf4, () -> atomicInt.incrementAndGet(), executor); checkCompletedExceptionally(cf4); checkCompletedNormally(cf5, 1); checkCompletedExceptionally(cf3); @@ -472,7 +472,7 @@ before = atomicInt.get(); cf4 = supplyAsync(() -> 1); cf5 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf5.runAfterBothAsync(cf4, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf5.runAfterBothAsync(cf4, () -> atomicInt.incrementAndGet()); checkCompletedNormally(cf4, 1); checkCompletedExceptionally(cf5); checkCompletedExceptionally(cf3); @@ -481,7 +481,7 @@ before = atomicInt.get(); cf4 = supplyAsync(() -> { throw new RuntimeException(); }); cf5 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf5.runAfterBoth(cf4, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf5.runAfterBoth(cf4, () -> atomicInt.incrementAndGet()); checkCompletedExceptionally(cf4); checkCompletedExceptionally(cf5); checkCompletedExceptionally(cf3); @@ -495,46 +495,46 @@ CompletableFuture cf3; CompletableFuture cf1 = supplyAsync(() -> 1); CompletableFuture cf2 = supplyAsync(() -> 2); - cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 1 || x == 2); return x; }); + cf3 = cf1.applyToEither(cf2, x -> { check(x == 1 || x == 2); return x; }); checkCompletedNormally(cf3, new Object[] {1, 2}); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> 2); - cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); return x; }); + cf3 = cf1.applyToEitherAsync(cf2, x -> { check(x == 1 || x == 2); return x; }); checkCompletedNormally(cf3, new Object[] {1, 2}); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> 2); - cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); return x; }, executor); + cf3 = cf1.applyToEitherAsync(cf2, x -> { check(x == 1 || x == 2); return x; }, executor); checkCompletedNormally(cf3, new Object[] {1, 2}); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> 2); - cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; }); + cf3 = cf1.applyToEither(cf2, x -> { check(x == 2); return x; }); try { check(cf3.join() == 2); } catch (CompletionException x) { pass(); } check(cf3.isDone()); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1); return x; }); + cf3 = cf1.applyToEitherAsync(cf2, x -> { check(x == 1); return x; }); try { check(cf3.join() == 1); } catch (CompletionException x) { pass(); } check(cf3.isDone()); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.applyToEitherAsync(cf2, (x) -> { fail(); return x; }); + cf3 = cf1.applyToEitherAsync(cf2, x -> { fail(); return x; }); checkCompletedExceptionally(cf3); check(cf1.isDone() || cf2.isDone()); final Phaser cf3Done = new Phaser(2); cf1 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 1; }); cf2 = supplyAsync(() -> 2); - cf3 = cf1.applyToEither(cf2, (x) -> { check(x == 2); return x; }); + cf3 = cf1.applyToEither(cf2, x -> { check(x == 2); return x; }); checkCompletedNormally(cf3, 2); checkCompletedNormally(cf2, 2); check(!cf1.isDone()); @@ -544,7 +544,7 @@ cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 2; }); - cf3 = cf1.applyToEitherAsync(cf2, (x) -> { check(x == 1); return x; }); + cf3 = cf1.applyToEitherAsync(cf2, x -> { check(x == 1); return x; }); checkCompletedNormally(cf3, 1); checkCompletedNormally(cf1, 1); check(!cf2.isDone()); @@ -561,15 +561,7 @@ int before = atomicInt.get(); CompletableFuture cf1 = supplyAsync(() -> 1); CompletableFuture cf2 = supplyAsync(() -> 2); - cf3 = cf1.acceptEither(cf2, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }); - checkCompletedNormally(cf3, null); - check(cf1.isDone() || cf2.isDone()); - check(atomicInt.get() == (before + 1)); - - before = atomicInt.get(); - cf1 = supplyAsync(() -> 1); - cf2 = supplyAsync(() -> 2); - cf3 = cf1.acceptEitherAsync(cf2, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }); + cf3 = cf1.acceptEither(cf2, x -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }); checkCompletedNormally(cf3, null); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == (before + 1)); @@ -577,35 +569,43 @@ before = atomicInt.get(); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> 2); - cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }, executor); + cf3 = cf1.acceptEitherAsync(cf2, x -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }); + checkCompletedNormally(cf3, null); + check(cf1.isDone() || cf2.isDone()); + check(atomicInt.get() == (before + 1)); + + before = atomicInt.get(); + cf1 = supplyAsync(() -> 1); + cf2 = supplyAsync(() -> 2); + cf3 = cf2.acceptEitherAsync(cf1, x -> { check(x == 1 || x == 2); atomicInt.incrementAndGet(); }, executor); checkCompletedNormally(cf3, null); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == (before + 1)); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> 2); - cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 2); }, executor); + cf3 = cf2.acceptEitherAsync(cf1, x -> { check(x == 2); }, executor); try { check(cf3.join() == null); } catch (CompletionException x) { pass(); } check(cf3.isDone()); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf2.acceptEitherAsync(cf1, (x) -> { check(x == 1); }); + cf3 = cf2.acceptEitherAsync(cf1, x -> { check(x == 1); }); try { check(cf3.join() == null); } catch (CompletionException x) { pass(); } check(cf3.isDone()); check(cf1.isDone() || cf2.isDone()); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); cf2 = supplyAsync(() -> { throw new RuntimeException(); }); - cf3 = cf2.acceptEitherAsync(cf1, (x) -> { fail(); }); + cf3 = cf2.acceptEitherAsync(cf1, x -> { fail(); }); checkCompletedExceptionally(cf3); check(cf1.isDone() || cf2.isDone()); final Phaser cf3Done = new Phaser(2); cf1 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 1; }); cf2 = supplyAsync(() -> 2); - cf3 = cf1.acceptEither(cf2, (x) -> { check(x == 2); }); + cf3 = cf1.acceptEither(cf2, x -> { check(x == 2); }); checkCompletedNormally(cf3, null); checkCompletedNormally(cf2, 2); check(!cf1.isDone()); @@ -615,7 +615,7 @@ cf1 = supplyAsync(() -> 1); cf2 = supplyAsync(() -> { cf3Done.arriveAndAwaitAdvance(); return 2; }); - cf3 = cf1.acceptEitherAsync(cf2, (x) -> { check(x == 1); }); + cf3 = cf1.acceptEitherAsync(cf2, x -> { check(x == 1); }); checkCompletedNormally(cf3, null); checkCompletedNormally(cf1, 1); check(!cf2.isDone()); @@ -632,7 +632,7 @@ int before = atomicInt.get(); CompletableFuture cf1 = runAsync(() -> { }); CompletableFuture cf2 = runAsync(() -> { }); - cf3 = cf1.runAfterEither(cf2, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.runAfterEither(cf2, () -> atomicInt.incrementAndGet()); checkCompletedNormally(cf3, null); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == (before + 1)); @@ -640,7 +640,7 @@ before = atomicInt.get(); cf1 = runAsync(() -> { }); cf2 = runAsync(() -> { }); - cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.runAfterEitherAsync(cf2, () -> atomicInt.incrementAndGet()); checkCompletedNormally(cf3, null); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == (before + 1)); @@ -648,7 +648,7 @@ before = atomicInt.get(); cf1 = runAsync(() -> { }); cf2 = runAsync(() -> { }); - cf3 = cf2.runAfterEitherAsync(cf1, () -> { atomicInt.incrementAndGet(); }, executor); + cf3 = cf2.runAfterEitherAsync(cf1, () -> atomicInt.incrementAndGet(), executor); checkCompletedNormally(cf3, null); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == (before + 1)); @@ -656,7 +656,7 @@ before = atomicInt.get(); cf1 = runAsync(() -> { throw new RuntimeException(); }); cf2 = runAsync(() -> { }); - cf3 = cf2.runAfterEither(cf1, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf2.runAfterEither(cf1, () -> atomicInt.incrementAndGet()); try { check(cf3.join() == null); check(atomicInt.get() == (before + 1)); @@ -667,7 +667,7 @@ before = atomicInt.get(); cf1 = runAsync(() -> { }); cf2 = runAsync(() -> { throw new RuntimeException(); }); - cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.runAfterEitherAsync(cf2, () -> atomicInt.incrementAndGet()); try { check(cf3.join() == null); check(atomicInt.get() == (before + 1)); @@ -678,16 +678,16 @@ before = atomicInt.get(); cf1 = runAsync(() -> { throw new RuntimeException(); }); cf2 = runAsync(() -> { throw new RuntimeException(); }); - cf3 = cf2.runAfterEitherAsync(cf1, () -> { atomicInt.incrementAndGet(); }, executor); + cf3 = cf2.runAfterEitherAsync(cf1, () -> atomicInt.incrementAndGet(), executor); checkCompletedExceptionally(cf3); check(cf1.isDone() || cf2.isDone()); check(atomicInt.get() == before); final Phaser cf3Done = new Phaser(2); before = atomicInt.get(); - cf1 = runAsync(() -> { cf3Done.arriveAndAwaitAdvance(); }); + cf1 = runAsync(() -> cf3Done.arriveAndAwaitAdvance()); cf2 = runAsync(() -> { }); - cf3 = cf1.runAfterEither(cf2, () -> { atomicInt.incrementAndGet(); }); + cf3 = cf1.runAfterEither(cf2, () -> atomicInt.incrementAndGet()); checkCompletedNormally(cf3, null); checkCompletedNormally(cf2, null); check(!cf1.isDone()); @@ -698,8 +698,8 @@ before = atomicInt.get(); cf1 = runAsync(() -> { }); - cf2 = runAsync(() -> { cf3Done.arriveAndAwaitAdvance(); }); - cf3 = cf1.runAfterEitherAsync(cf2, () -> { atomicInt.incrementAndGet(); }); + cf2 = runAsync(() -> cf3Done.arriveAndAwaitAdvance()); + cf3 = cf1.runAfterEitherAsync(cf2, () -> atomicInt.incrementAndGet()); checkCompletedNormally(cf3, null); checkCompletedNormally(cf1, null); check(!cf2.isDone()); @@ -715,35 +715,35 @@ try { CompletableFuture cf2; CompletableFuture cf1 = supplyAsync(() -> 1); - cf2 = cf1.thenCompose((x) -> { check(x ==1); return CompletableFuture.completedFuture(2); }); + cf2 = cf1.thenCompose(x -> { check(x == 1); return CompletableFuture.completedFuture(2); }); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 2); cf1 = supplyAsync(() -> 1); - cf2 = cf1.thenComposeAsync((x) -> { check(x ==1); return CompletableFuture.completedFuture(2); }); + cf2 = cf1.thenComposeAsync(x -> { check(x == 1); return CompletableFuture.completedFuture(2); }); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 2); cf1 = supplyAsync(() -> 1); - cf2 = cf1.thenComposeAsync((x) -> { check(x ==1); return CompletableFuture.completedFuture(2); }, executor); + cf2 = cf1.thenComposeAsync(x -> { check(x == 1); return CompletableFuture.completedFuture(2); }, executor); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 2); int before = atomicInt.get(); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenCompose((x) -> { atomicInt.incrementAndGet(); return CompletableFuture.completedFuture(2); }); + cf2 = cf1.thenCompose(x -> { atomicInt.incrementAndGet(); return CompletableFuture.completedFuture(2); }); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> { throw new RuntimeException(); }); - cf2 = cf1.thenComposeAsync((x) -> { atomicInt.incrementAndGet(); return CompletableFuture.completedFuture(2); }); + cf2 = cf1.thenComposeAsync(x -> { atomicInt.incrementAndGet(); return CompletableFuture.completedFuture(2); }); checkCompletedExceptionally(cf1); checkCompletedExceptionally(cf2); check(atomicInt.get() == before); cf1 = supplyAsync(() -> 1); - cf2 = cf1.thenComposeAsync((x) -> { throw new RuntimeException(); }, executor); + cf2 = cf1.thenComposeAsync(x -> { throw new RuntimeException(); }, executor); checkCompletedNormally(cf1, 1); checkCompletedExceptionally(cf2); } catch (Throwable t) { unexpected(t); } @@ -787,13 +787,13 @@ try { CompletableFuture cf2; CompletableFuture cf1 = supplyAsync(() -> 1); - cf2 = cf1.exceptionally((t) -> { fail("function should never be called"); return 2;}); + cf2 = cf1.exceptionally(t -> { fail("function should never be called"); return 2;}); checkCompletedNormally(cf1, 1); checkCompletedNormally(cf2, 1); final RuntimeException t = new RuntimeException(); cf1 = supplyAsync(() -> { throw t; }); - cf2 = cf1.exceptionally((x) -> { check(x.getCause() == t); return 2;}); + cf2 = cf1.exceptionally(x -> { check(x.getCause() == t); return 2;}); checkCompletedExceptionally(cf1); checkCompletedNormally(cf2, 2); } catch (Throwable t) { unexpected(t); } diff --git a/test/jdk/java/util/concurrent/ConcurrentHashMap/LoopHelpers.java b/test/jdk/java/util/concurrent/ConcurrentHashMap/LoopHelpers.java --- a/test/jdk/java/util/concurrent/ConcurrentHashMap/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java --- a/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java +++ b/test/jdk/java/util/concurrent/ConcurrentHashMap/MapCheck.java @@ -109,8 +109,7 @@ static Map newMap(Class cl) { try { - Map m = (Map)cl.newInstance(); - return m; + return (Map)cl.newInstance(); } catch (Exception e) { throw new RuntimeException("Can't instantiate " + cl + ": " + e); } diff --git a/test/jdk/java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java b/test/jdk/java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java --- a/test/jdk/java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java +++ b/test/jdk/java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java @@ -55,7 +55,6 @@ import java.util.concurrent.ThreadLocalRandom; import static java.util.stream.Collectors.toList; import java.util.function.Consumer; -import java.util.function.Function; @Test public class WhiteBox { diff --git a/test/jdk/java/util/concurrent/ConcurrentQueues/LoopHelpers.java b/test/jdk/java/util/concurrent/ConcurrentQueues/LoopHelpers.java --- a/test/jdk/java/util/concurrent/ConcurrentQueues/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/ConcurrentQueues/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java b/test/jdk/java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java --- a/test/jdk/java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java +++ b/test/jdk/java/util/concurrent/ConcurrentQueues/OfferRemoveLoops.java @@ -81,7 +81,7 @@ final CountDownLatch done = new CountDownLatch(3); final SplittableRandom rnd = new SplittableRandom(); - /** Poor man's bounded buffer; prevents unbounded queue expansion. */ + // Poor man's bounded buffer; prevents unbounded queue expansion. final Semaphore offers = new Semaphore(maxQueueSize); abstract class CheckedThread extends Thread { diff --git a/test/jdk/java/util/concurrent/Exchanger/LoopHelpers.java b/test/jdk/java/util/concurrent/Exchanger/LoopHelpers.java --- a/test/jdk/java/util/concurrent/Exchanger/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/Exchanger/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java b/test/jdk/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java --- a/test/jdk/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java +++ b/test/jdk/java/util/concurrent/ExecutorCompletionService/ExecutorCompletionServiceLoops.java @@ -52,7 +52,7 @@ static final ExecutorService pool = Executors.newFixedThreadPool(POOLSIZE); static final ExecutorCompletionService ecs = - new ExecutorCompletionService(pool); + new ExecutorCompletionService<>(pool); static boolean print = false; public static void main(String[] args) throws Exception { diff --git a/test/jdk/java/util/concurrent/ExecutorCompletionService/LoopHelpers.java b/test/jdk/java/util/concurrent/ExecutorCompletionService/LoopHelpers.java --- a/test/jdk/java/util/concurrent/ExecutorCompletionService/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/ExecutorCompletionService/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/FutureTask/BlockingTaskExecutor.java b/test/jdk/java/util/concurrent/FutureTask/BlockingTaskExecutor.java --- a/test/jdk/java/util/concurrent/FutureTask/BlockingTaskExecutor.java +++ b/test/jdk/java/util/concurrent/FutureTask/BlockingTaskExecutor.java @@ -26,21 +26,25 @@ * @bug 6431315 * @summary ExecutorService.invokeAll might hang * @author Martin Buchholz + * @library /lib/testlibrary/ */ +import static java.util.concurrent.TimeUnit.MILLISECONDS; + import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.TimeUnit; +import jdk.testlibrary.Utils; /** * Adapted from Doug Lea, which was... * adapted from a posting by Tom Sugden tom at epcc.ed.ac.uk */ public class BlockingTaskExecutor { + static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000); static void realMain(String[] args) throws Throwable { for (int i = 1; i <= 100; i++) { @@ -75,15 +79,19 @@ // are blocked. This should cause the tasks to be // interrupted. executor.shutdownNow(); - if (! executor.awaitTermination(5L, TimeUnit.SECONDS)) - throw new Error("Executor stuck"); + if (! executor.awaitTermination(LONG_DELAY_MS, MILLISECONDS)) + throw new Error( + String.format("Executor termination timed out after %d ms", + LONG_DELAY_MS)); // Wait for the invocation thread to complete. - thread.join(5000); + thread.join(LONG_DELAY_MS); if (thread.isAlive()) { thread.interrupt(); - thread.join(5000); - throw new Error("invokeAll stuck"); + thread.join(LONG_DELAY_MS); + throw new Error( + String.format("invokeAll timed out after %d ms", + LONG_DELAY_MS)); } } diff --git a/test/jdk/java/util/concurrent/FutureTask/ExplicitSet.java b/test/jdk/java/util/concurrent/FutureTask/ExplicitSet.java --- a/test/jdk/java/util/concurrent/FutureTask/ExplicitSet.java +++ b/test/jdk/java/util/concurrent/FutureTask/ExplicitSet.java @@ -60,7 +60,7 @@ public Boolean call() { fail("The task should never be run!"); return null; - }; + } }); } diff --git a/test/jdk/java/util/concurrent/FutureTask/LoopHelpers.java b/test/jdk/java/util/concurrent/FutureTask/LoopHelpers.java --- a/test/jdk/java/util/concurrent/FutureTask/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/FutureTask/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/FutureTask/NegativeTimeout.java b/test/jdk/java/util/concurrent/FutureTask/NegativeTimeout.java --- a/test/jdk/java/util/concurrent/FutureTask/NegativeTimeout.java +++ b/test/jdk/java/util/concurrent/FutureTask/NegativeTimeout.java @@ -38,7 +38,7 @@ public class NegativeTimeout { public static void main(String[] args) throws Exception { - FutureTask task = new FutureTask<>( () -> { return null; } ); + FutureTask task = new FutureTask<>(() -> null); try { task.get(Long.MIN_VALUE, TimeUnit.NANOSECONDS); } catch (TimeoutException success) {} diff --git a/test/jdk/java/util/concurrent/LinkedTransferQueue/WhiteBox.java b/test/jdk/java/util/concurrent/LinkedTransferQueue/WhiteBox.java --- a/test/jdk/java/util/concurrent/LinkedTransferQueue/WhiteBox.java +++ b/test/jdk/java/util/concurrent/LinkedTransferQueue/WhiteBox.java @@ -56,7 +56,6 @@ import java.util.concurrent.TimeUnit; import static java.util.stream.Collectors.toList; import java.util.function.Consumer; -import java.util.function.Function; @Test public class WhiteBox { diff --git a/test/jdk/java/util/concurrent/atomic/AtomicUpdaters.java b/test/jdk/java/util/concurrent/atomic/AtomicUpdaters.java --- a/test/jdk/java/util/concurrent/atomic/AtomicUpdaters.java +++ b/test/jdk/java/util/concurrent/atomic/AtomicUpdaters.java @@ -89,9 +89,9 @@ // Would like to test a public volatile in a class in another // package - but of course there aren't any - new Config(AtomicInteger.class, "value", "private", hasSM ? false : true, false, "private int field of class in different package", TYPE.INT), - new Config(AtomicLong.class, "value", "private", hasSM ? false : true, false, "private long field of class in different package", TYPE.LONG), - new Config(AtomicReference.class, "value", "private", hasSM ? false : true, false, "private reference field of class in different package", TYPE.REF), + new Config(AtomicInteger.class, "value", "private", !hasSM, false, "private int field of class in different package", TYPE.INT), + new Config(AtomicLong.class, "value", "private", !hasSM, false, "private long field of class in different package", TYPE.LONG), + new Config(AtomicReference.class, "value", "private", !hasSM, false, "private reference field of class in different package", TYPE.REF), }; } diff --git a/test/jdk/java/util/concurrent/locks/Lock/LoopHelpers.java b/test/jdk/java/util/concurrent/locks/Lock/LoopHelpers.java --- a/test/jdk/java/util/concurrent/locks/Lock/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/locks/Lock/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/locks/ReentrantLock/LoopHelpers.java b/test/jdk/java/util/concurrent/locks/ReentrantLock/LoopHelpers.java --- a/test/jdk/java/util/concurrent/locks/ReentrantLock/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/locks/ReentrantLock/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java b/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java --- a/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java +++ b/test/jdk/java/util/concurrent/locks/ReentrantReadWriteLock/LoopHelpers.java @@ -95,7 +95,7 @@ String num = Long.toString(n); if (num.length() >= field.length()) return num; - StringBuffer b = new StringBuffer(field); + StringBuilder b = new StringBuilder(field); b.replace(b.length()-num.length(), b.length(), num); return b.toString(); } diff --git a/test/jdk/java/util/concurrent/tck/AbstractQueueTest.java b/test/jdk/java/util/concurrent/tck/AbstractQueueTest.java --- a/test/jdk/java/util/concurrent/tck/AbstractQueueTest.java +++ b/test/jdk/java/util/concurrent/tck/AbstractQueueTest.java @@ -80,7 +80,7 @@ } /** - * add throws IllegalStateException true if offer fails + * add throws IllegalStateException if offer fails */ public void testAddF() { Fail q = new Fail(); @@ -106,7 +106,7 @@ */ public void testRemoveS() { Succeed q = new Succeed(); - q.remove(); + assertSame(one, q.remove()); } /** @@ -125,7 +125,7 @@ */ public void testElementS() { Succeed q = new Succeed(); - q.element(); + assertSame(one, q.element()); } /** diff --git a/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java --- a/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java +++ b/test/jdk/java/util/concurrent/tck/AbstractQueuedSynchronizerTest.java @@ -1289,11 +1289,10 @@ } /** - * Disabled demo test for (unfixed as of 2017-11) * JDK-8191483: AbstractQueuedSynchronizer cancel/cancel race * ant -Djsr166.tckTestClass=AbstractQueuedSynchronizerTest -Djsr166.methodFilter=testCancelCancelRace -Djsr166.runsPerTest=100 tck */ - public void DISABLED_testCancelCancelRace() throws InterruptedException { + public void testCancelCancelRace() throws InterruptedException { class Sync extends AbstractQueuedSynchronizer { protected boolean tryAcquire(int acquires) { return !hasQueuedPredecessors() && compareAndSetState(0, 1); diff --git a/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java b/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java --- a/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java +++ b/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java @@ -110,14 +110,13 @@ assertEquals((Integer) 1, q.peekLast()); assertEquals(maxArraySize - 1, q.size()); - ArrayDeque qq = q; ArrayDeque smallish = new ArrayDeque( Collections.nCopies(Integer.MAX_VALUE - q.size() + 1, e)); assertThrows( IllegalStateException.class, - () -> qq.addAll(qq), - () -> qq.addAll(smallish), - () -> smallish.addAll(qq)); + () -> q.addAll(q), + () -> q.addAll(smallish), + () -> smallish.addAll(q)); } } diff --git a/test/jdk/java/util/concurrent/tck/AtomicReferenceArrayTest.java b/test/jdk/java/util/concurrent/tck/AtomicReferenceArrayTest.java --- a/test/jdk/java/util/concurrent/tck/AtomicReferenceArrayTest.java +++ b/test/jdk/java/util/concurrent/tck/AtomicReferenceArrayTest.java @@ -84,7 +84,7 @@ */ public void testConstructorSubClassArray() { Integer[] a = { two, one, three, four, seven }; - AtomicReferenceArray aa = new AtomicReferenceArray(a); + AtomicReferenceArray aa = new AtomicReferenceArray<>(a); assertEquals(a.length, aa.length()); for (int i = 0; i < a.length; i++) { assertSame(a[i], aa.get(i)); diff --git a/test/jdk/java/util/concurrent/tck/BlockingQueueTest.java b/test/jdk/java/util/concurrent/tck/BlockingQueueTest.java --- a/test/jdk/java/util/concurrent/tck/BlockingQueueTest.java +++ b/test/jdk/java/util/concurrent/tck/BlockingQueueTest.java @@ -216,18 +216,20 @@ public void testDrainToNonPositiveMaxElements() { final BlockingQueue q = emptyCollection(); final int[] ns = { 0, -1, -42, Integer.MIN_VALUE }; - for (int n : ns) - assertEquals(0, q.drainTo(new ArrayList(), n)); + final ArrayList sink = new ArrayList(); + for (int n : ns) { + assertEquals(0, q.drainTo(sink, n)); + assertTrue(sink.isEmpty()); + } if (q.remainingCapacity() > 0) { // Not SynchronousQueue, that is Object one = makeElement(1); q.add(one); - ArrayList c = new ArrayList(); for (int n : ns) - assertEquals(0, q.drainTo(new ArrayList(), n)); + assertEquals(0, q.drainTo(sink, n)); assertEquals(1, q.size()); assertSame(one, q.poll()); - assertTrue(c.isEmpty()); + assertTrue(sink.isEmpty()); } } diff --git a/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java b/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java --- a/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java +++ b/test/jdk/java/util/concurrent/tck/CompletableFutureTest.java @@ -357,7 +357,7 @@ * toString indicates current completion state */ public void testToString_incomplete() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); if (testImplementationDetails) assertEquals(identityString(f) + "[Not completed]", @@ -365,7 +365,7 @@ } public void testToString_normal() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.complete("foo")); assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); if (testImplementationDetails) @@ -374,7 +374,7 @@ } public void testToString_exception() { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.completeExceptionally(new IndexOutOfBoundsException())); assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); if (testImplementationDetails) @@ -384,7 +384,7 @@ public void testToString_cancelled() { for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { - CompletableFuture f = new CompletableFuture(); + CompletableFuture f = new CompletableFuture<>(); assertTrue(f.cancel(mayInterruptIfRunning)); assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); if (testImplementationDetails) diff --git a/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java b/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java --- a/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java +++ b/test/jdk/java/util/concurrent/tck/ConcurrentHashMap8Test.java @@ -212,7 +212,7 @@ */ public void testReplaceAll() { ConcurrentHashMap map = map5(); - map.replaceAll((x, y) -> { return x > 3 ? "Z" : y; }); + map.replaceAll((x, y) -> (x > 3) ? "Z" : y); assertEquals("A", map.get(one)); assertEquals("B", map.get(two)); assertEquals("C", map.get(three)); diff --git a/test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java b/test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java --- a/test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java +++ b/test/jdk/java/util/concurrent/tck/ConcurrentHashMapTest.java @@ -83,17 +83,12 @@ return map; } - /** Re-implement Integer.compare for old java versions */ - static int compare(int x, int y) { - return (x < y) ? -1 : (x > y) ? 1 : 0; - } - // classes for testing Comparable fallbacks static class BI implements Comparable { private final int value; BI(int value) { this.value = value; } public int compareTo(BI other) { - return compare(value, other.value); + return Integer.compare(value, other.value); } public boolean equals(Object x) { return (x instanceof BI) && ((BI)x).value == value; @@ -127,7 +122,7 @@ break; } if (r == 0) - r = compare(size(), other.size()); + r = Integer.compare(size(), other.size()); return r; } private static final long serialVersionUID = 0; @@ -155,8 +150,7 @@ */ public void testComparableFamily() { int size = 500; // makes measured test run time -> 60ms - ConcurrentHashMap m = - new ConcurrentHashMap(); + ConcurrentHashMap m = new ConcurrentHashMap<>(); for (int i = 0; i < size; i++) { assertNull(m.put(new CI(i), true)); } @@ -172,13 +166,12 @@ */ public void testGenericComparable() { int size = 120; // makes measured test run time -> 60ms - ConcurrentHashMap m = - new ConcurrentHashMap(); + ConcurrentHashMap m = new ConcurrentHashMap<>(); for (int i = 0; i < size; i++) { BI bi = new BI(i); BS bs = new BS(String.valueOf(i)); - LexicographicList bis = new LexicographicList(bi); - LexicographicList bss = new LexicographicList(bs); + LexicographicList bis = new LexicographicList<>(bi); + LexicographicList bss = new LexicographicList<>(bs); assertNull(m.putIfAbsent(bis, true)); assertTrue(m.containsKey(bis)); if (m.putIfAbsent(bss, true) == null) @@ -197,14 +190,13 @@ */ public void testGenericComparable2() { int size = 500; // makes measured test run time -> 60ms - ConcurrentHashMap m = - new ConcurrentHashMap(); + ConcurrentHashMap m = new ConcurrentHashMap<>(); for (int i = 0; i < size; i++) { m.put(Collections.singletonList(new BI(i)), true); } for (int i = 0; i < size; i++) { - LexicographicList bis = new LexicographicList(new BI(i)); + LexicographicList bis = new LexicographicList<>(new BI(i)); assertTrue(m.containsKey(bis)); } } @@ -215,8 +207,7 @@ */ public void testMixedComparable() { int size = 1200; // makes measured test run time -> 35ms - ConcurrentHashMap map = - new ConcurrentHashMap(); + ConcurrentHashMap map = new ConcurrentHashMap<>(); Random rng = new Random(); for (int i = 0; i < size; i++) { Object x; diff --git a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java --- a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java +++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSetTest.java @@ -65,8 +65,7 @@ * Integers 0 ... n - 1. */ private static ConcurrentSkipListSet populatedSet(int n) { - ConcurrentSkipListSet q = - new ConcurrentSkipListSet(); + ConcurrentSkipListSet q = new ConcurrentSkipListSet<>(); assertTrue(q.isEmpty()); for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.add(new Integer(i))); diff --git a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java --- a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java +++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListSubSetTest.java @@ -60,8 +60,7 @@ * Integers 0 ... n - 1. */ private static NavigableSet populatedSet(int n) { - ConcurrentSkipListSet q = - new ConcurrentSkipListSet(); + ConcurrentSkipListSet q = new ConcurrentSkipListSet<>(); assertTrue(q.isEmpty()); for (int i = n - 1; i >= 0; i -= 2) diff --git a/test/jdk/java/util/concurrent/tck/CopyOnWriteArrayListTest.java b/test/jdk/java/util/concurrent/tck/CopyOnWriteArrayListTest.java --- a/test/jdk/java/util/concurrent/tck/CopyOnWriteArrayListTest.java +++ b/test/jdk/java/util/concurrent/tck/CopyOnWriteArrayListTest.java @@ -83,8 +83,8 @@ static CopyOnWriteArrayList populatedArray(Integer[] elements) { CopyOnWriteArrayList a = new CopyOnWriteArrayList<>(); assertTrue(a.isEmpty()); - for (int i = 0; i < elements.length; i++) - a.add(elements[i]); + for (Integer element : elements) + a.add(element); assertFalse(a.isEmpty()); assertEquals(elements.length, a.size()); return a; diff --git a/test/jdk/java/util/concurrent/tck/CyclicBarrierTest.java b/test/jdk/java/util/concurrent/tck/CyclicBarrierTest.java --- a/test/jdk/java/util/concurrent/tck/CyclicBarrierTest.java +++ b/test/jdk/java/util/concurrent/tck/CyclicBarrierTest.java @@ -335,8 +335,7 @@ c.await(); shouldThrow(); } - catch (BrokenBarrierException ok) {} - catch (InterruptedException ok) {} + catch (BrokenBarrierException | InterruptedException ok) {} }}}); for (int i = 0; i < 4; i++) { diff --git a/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java b/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java --- a/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java +++ b/test/jdk/java/util/concurrent/tck/ForkJoinPool8Test.java @@ -1557,7 +1557,7 @@ * timeout elapsed */ public void testAwaitQuiescence2() throws Exception { - /** + /* * """It is possible to disable or limit the use of threads in the * common pool by setting the parallelism property to zero. However * doing so may cause unjoined tasks to never be executed.""" diff --git a/test/jdk/java/util/concurrent/tck/FutureTaskTest.java b/test/jdk/java/util/concurrent/tck/FutureTaskTest.java --- a/test/jdk/java/util/concurrent/tck/FutureTaskTest.java +++ b/test/jdk/java/util/concurrent/tck/FutureTaskTest.java @@ -865,7 +865,7 @@ * toString indicates current completion state */ public void testToString_incomplete() { - FutureTask f = new FutureTask(() -> ""); + FutureTask f = new FutureTask<>(() -> ""); assertTrue(f.toString().matches(".*\\[.*Not completed.*\\]")); if (testImplementationDetails) assertTrue(f.toString().startsWith( @@ -873,7 +873,7 @@ } public void testToString_normal() { - FutureTask f = new FutureTask(() -> ""); + FutureTask f = new FutureTask<>(() -> ""); f.run(); assertTrue(f.toString().matches(".*\\[.*Completed normally.*\\]")); if (testImplementationDetails) @@ -882,7 +882,7 @@ } public void testToString_exception() { - FutureTask f = new FutureTask( + FutureTask f = new FutureTask<>( () -> { throw new ArithmeticException(); }); f.run(); assertTrue(f.toString().matches(".*\\[.*Completed exceptionally.*\\]")); @@ -893,7 +893,7 @@ public void testToString_cancelled() { for (boolean mayInterruptIfRunning : new boolean[] { true, false }) { - FutureTask f = new FutureTask(() -> ""); + FutureTask f = new FutureTask<>(() -> ""); assertTrue(f.cancel(mayInterruptIfRunning)); assertTrue(f.toString().matches(".*\\[.*Cancelled.*\\]")); if (testImplementationDetails) diff --git a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java --- a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java +++ b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java @@ -475,15 +475,8 @@ public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } - public static boolean atLeastJava9() { - return JAVA_CLASS_VERSION >= 53.0 - // As of 2015-09, java9 still uses 52.0 class file version - || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?(9|[0-9][0-9])$"); - } - public static boolean atLeastJava10() { - return JAVA_CLASS_VERSION >= 54.0 - || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?[0-9][0-9]$"); - } + public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; } + public static boolean atLeastJava10() { return JAVA_CLASS_VERSION >= 54.0; } /** * Collects all JSR166 unit tests as one suite. diff --git a/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java b/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java --- a/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java +++ b/test/jdk/java/util/concurrent/tck/LinkedBlockingQueueTest.java @@ -86,8 +86,7 @@ * Integers 0 ... n - 1. */ private static LinkedBlockingQueue populatedQueue(int n) { - LinkedBlockingQueue q = - new LinkedBlockingQueue(n); + LinkedBlockingQueue q = new LinkedBlockingQueue<>(n); assertTrue(q.isEmpty()); for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i))); diff --git a/test/jdk/java/util/concurrent/tck/MapTest.java b/test/jdk/java/util/concurrent/tck/MapTest.java --- a/test/jdk/java/util/concurrent/tck/MapTest.java +++ b/test/jdk/java/util/concurrent/tck/MapTest.java @@ -129,7 +129,7 @@ final Object v2 = (permitsNullValues && rnd.nextBoolean() && v1 != null) ? null : impl.makeValue(2); - /** If true, always lands in first bucket in hash tables. */ + // If true, always lands in first bucket in hash tables. final boolean poorHash = rnd.nextBoolean(); class Key implements Comparable { final int i; diff --git a/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java b/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java --- a/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java +++ b/test/jdk/java/util/concurrent/tck/RecursiveActionTest.java @@ -352,8 +352,7 @@ * succeeds in the presence of interrupts */ public void testJoinIgnoresInterruptsOutsideForkJoinPool() { - final SynchronousQueue sq = - new SynchronousQueue(); + final SynchronousQueue sq = new SynchronousQueue<>(); RecursiveAction a = new CheckedRecursiveAction() { protected void realCompute() throws InterruptedException { FibAction[] fibActions = new FibAction[6]; diff --git a/test/jdk/java/util/concurrent/tck/ScheduledExecutorSubclassTest.java b/test/jdk/java/util/concurrent/tck/ScheduledExecutorSubclassTest.java --- a/test/jdk/java/util/concurrent/tck/ScheduledExecutorSubclassTest.java +++ b/test/jdk/java/util/concurrent/tck/ScheduledExecutorSubclassTest.java @@ -872,7 +872,7 @@ immediates.forEach( f -> assertTrue(((ScheduledFuture)f).getDelay(NANOSECONDS) <= 0L)); - Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream()) + Stream.of(immediates, delayeds, periodics).flatMap(Collection::stream) .forEach(f -> assertFalse(f.isDone())); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -926,7 +926,7 @@ assertTrue(q.isEmpty()); - Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream()) + Stream.of(immediates, delayeds, periodics).flatMap(Collection::stream) .forEach(f -> assertTrue(f.isDone())); for (Future f : immediates) assertNull(f.get()); diff --git a/test/jdk/java/util/concurrent/tck/ScheduledExecutorTest.java b/test/jdk/java/util/concurrent/tck/ScheduledExecutorTest.java --- a/test/jdk/java/util/concurrent/tck/ScheduledExecutorTest.java +++ b/test/jdk/java/util/concurrent/tck/ScheduledExecutorTest.java @@ -831,7 +831,7 @@ immediates.forEach( f -> assertTrue(((ScheduledFuture)f).getDelay(NANOSECONDS) <= 0L)); - Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream()) + Stream.of(immediates, delayeds, periodics).flatMap(Collection::stream) .forEach(f -> assertFalse(f.isDone())); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -885,7 +885,7 @@ assertTrue(q.isEmpty()); - Stream.of(immediates, delayeds, periodics).flatMap(c -> c.stream()) + Stream.of(immediates, delayeds, periodics).flatMap(Collection::stream) .forEach(f -> assertTrue(f.isDone())); for (Future f : immediates) assertNull(f.get()); diff --git a/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java b/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java --- a/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java +++ b/test/jdk/java/util/concurrent/tck/SubmissionPublisherTest.java @@ -431,7 +431,7 @@ */ public void testCancel() { SubmissionPublisher p = - new SubmissionPublisher(basicExecutor, 4); // must be < 20 + new SubmissionPublisher<>(basicExecutor, 4); // must be < 20 TestSubscriber s1 = new TestSubscriber(); TestSubscriber s2 = new TestSubscriber(); p.subscribe(s1); @@ -1012,6 +1012,7 @@ * cvs update -D '2017-11-25' src/main/java/util/concurrent/SubmissionPublisher.java && ant -Djsr166.expensiveTests=true -Djsr166.tckTestClass=SubmissionPublisherTest -Djsr166.methodFilter=testMissedSignal tck; cvs update -A src/main/java/util/concurrent/SubmissionPublisher.java */ public void testMissedSignal_8187947() throws Exception { + if (!atLeastJava9()) return; // backport to jdk8 too hard final int N = expensiveTests ? (1 << 20) : (1 << 10); final CountDownLatch finished = new CountDownLatch(1); final SubmissionPublisher pub = new SubmissionPublisher<>(); diff --git a/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java b/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java --- a/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java +++ b/test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java @@ -382,7 +382,7 @@ // Don't use main thread's ThreadLocalRandom - it is likely to // be polluted by previous tests. final AtomicReference threadLocalRandom = - new AtomicReference(); + new AtomicReference<>(); final AtomicLong rand = new AtomicLong(); long firstRand = 0;