--- jsr166/src/test/tck/ExecutorsTest.java 2017/08/16 17:18:34 1.50 +++ jsr166/src/test/tck/ExecutorsTest.java 2022/03/22 21:29:23 1.56 @@ -63,7 +63,7 @@ public class ExecutorsTest extends JSR16 */ public void testNewCachedThreadPool3() { try { - ExecutorService e = Executors.newCachedThreadPool(null); + ExecutorService unused = Executors.newCachedThreadPool(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -97,7 +97,7 @@ public class ExecutorsTest extends JSR16 */ public void testNewSingleThreadExecutor3() { try { - ExecutorService e = Executors.newSingleThreadExecutor(null); + ExecutorService unused = Executors.newSingleThreadExecutor(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -145,7 +145,7 @@ public class ExecutorsTest extends JSR16 */ public void testNewFixedThreadPool3() { try { - ExecutorService e = Executors.newFixedThreadPool(2, null); + ExecutorService unused = Executors.newFixedThreadPool(2, null); shouldThrow(); } catch (NullPointerException success) {} } @@ -155,7 +155,7 @@ public class ExecutorsTest extends JSR16 */ public void testNewFixedThreadPool4() { try { - ExecutorService e = Executors.newFixedThreadPool(0); + ExecutorService unused = Executors.newFixedThreadPool(0); shouldThrow(); } catch (IllegalArgumentException success) {} } @@ -177,7 +177,8 @@ public class ExecutorsTest extends JSR16 */ public void testUnconfigurableExecutorServiceNPE() { try { - ExecutorService e = Executors.unconfigurableExecutorService(null); + ExecutorService unused = + Executors.unconfigurableExecutorService(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -187,7 +188,8 @@ public class ExecutorsTest extends JSR16 */ public void testUnconfigurableScheduledExecutorServiceNPE() { try { - ExecutorService e = Executors.unconfigurableScheduledExecutorService(null); + ExecutorService unused = + Executors.unconfigurableScheduledExecutorService(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -204,7 +206,7 @@ public class ExecutorsTest extends JSR16 await(proceed); }}; long startTime = System.nanoTime(); - Future f = p.schedule(Executors.callable(task, Boolean.TRUE), + Future f = p.schedule(Executors.callable(task, Boolean.TRUE), timeoutMillis(), MILLISECONDS); assertFalse(f.isDone()); proceed.countDown(); @@ -228,7 +230,7 @@ public class ExecutorsTest extends JSR16 await(proceed); }}; long startTime = System.nanoTime(); - Future f = p.schedule(Executors.callable(task, Boolean.TRUE), + Future f = p.schedule(Executors.callable(task, Boolean.TRUE), timeoutMillis(), MILLISECONDS); assertFalse(f.isDone()); proceed.countDown(); @@ -254,7 +256,7 @@ public class ExecutorsTest extends JSR16 await(proceed); }}; long startTime = System.nanoTime(); - Future f = p.schedule(Executors.callable(task, Boolean.TRUE), + Future f = p.schedule(Executors.callable(task, Boolean.TRUE), timeoutMillis(), MILLISECONDS); assertFalse(f.isDone()); proceed.countDown(); @@ -277,21 +279,24 @@ public class ExecutorsTest extends JSR16 Executors.newScheduledThreadPool(2), }; - final Runnable sleeper = new CheckedInterruptedRunnable() { + final CountDownLatch done = new CountDownLatch(1); + + final Runnable sleeper = new CheckedRunnable() { public void realRun() throws InterruptedException { - delay(LONG_DELAY_MS); + done.await(LONG_DELAY_MS, MILLISECONDS); }}; List threads = new ArrayList<>(); for (final ExecutorService executor : executors) { threads.add(newStartedThread(new CheckedRunnable() { public void realRun() { - Future future = executor.submit(sleeper); + Future future = executor.submit(sleeper); assertFutureTimesOut(future); }})); } for (Thread thread : threads) awaitTermination(thread); + done.countDown(); for (ExecutorService executor : executors) joinPool(executor); } @@ -300,6 +305,7 @@ public class ExecutorsTest extends JSR16 * ThreadPoolExecutor using defaultThreadFactory has * specified group, priority, daemon status, and name */ + @SuppressWarnings("removal") public void testDefaultThreadFactory() throws Exception { final ThreadGroup egroup = Thread.currentThread().getThreadGroup(); final CountDownLatch done = new CountDownLatch(1); @@ -330,6 +336,7 @@ public class ExecutorsTest extends JSR16 * specified group, priority, daemon status, name, * access control context and context class loader */ + @SuppressWarnings("removal") public void testPrivilegedThreadFactory() throws Exception { final CountDownLatch done = new CountDownLatch(1); Runnable r = new CheckedRunnable() { @@ -363,6 +370,7 @@ public class ExecutorsTest extends JSR16 new RuntimePermission("modifyThread")); } + @SuppressWarnings("removal") boolean haveCCLPermissions() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -376,6 +384,7 @@ public class ExecutorsTest extends JSR16 return true; } + @SuppressWarnings("removal") void checkCCL() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -395,6 +404,7 @@ public class ExecutorsTest extends JSR16 * Without class loader permissions, creating * privilegedCallableUsingCurrentClassLoader throws ACE */ + @SuppressWarnings("removal") public void testCreatePrivilegedCallableUsingCCLWithNoPrivs() { Runnable r = new CheckedRunnable() { public void realRun() throws Exception { @@ -413,6 +423,7 @@ public class ExecutorsTest extends JSR16 * With class loader permissions, calling * privilegedCallableUsingCurrentClassLoader does not throw ACE */ + @SuppressWarnings("removal") public void testPrivilegedCallableUsingCCLWithPrivs() throws Exception { Runnable r = new CheckedRunnable() { public void realRun() throws Exception { @@ -429,6 +440,7 @@ public class ExecutorsTest extends JSR16 /** * Without permissions, calling privilegedCallable throws ACE */ + @SuppressWarnings("removal") public void testPrivilegedCallableWithNoPrivs() throws Exception { // Avoid classloader-related SecurityExceptions in swingui.TestRunner Executors.privilegedCallable(new CheckCCL()); @@ -437,7 +449,7 @@ public class ExecutorsTest extends JSR16 public void realRun() throws Exception { if (System.getSecurityManager() == null) return; - Callable task = Executors.privilegedCallable(new CheckCCL()); + Callable task = Executors.privilegedCallable(new CheckCCL()); try { task.call(); shouldThrow(); @@ -501,6 +513,7 @@ public class ExecutorsTest extends JSR16 /** * With permissions, calling privilegedCallable succeeds */ + @SuppressWarnings("removal") public void testPrivilegedCallableWithPrivs() throws Exception { Runnable r = new CheckedRunnable() { public void realRun() throws Exception { @@ -516,7 +529,7 @@ public class ExecutorsTest extends JSR16 * callable(Runnable) returns null when called */ public void testCallable1() throws Exception { - Callable c = Executors.callable(new NoOpRunnable()); + Callable c = Executors.callable(new NoOpRunnable()); assertNull(c.call()); } @@ -524,7 +537,7 @@ public class ExecutorsTest extends JSR16 * callable(Runnable, result) returns result when called */ public void testCallable2() throws Exception { - Callable c = Executors.callable(new NoOpRunnable(), one); + Callable c = Executors.callable(new NoOpRunnable(), one); assertSame(one, c.call()); } @@ -532,7 +545,7 @@ public class ExecutorsTest extends JSR16 * callable(PrivilegedAction) returns its result when called */ public void testCallable3() throws Exception { - Callable c = Executors.callable(new PrivilegedAction() { + Callable c = Executors.callable(new PrivilegedAction() { public Object run() { return one; }}); assertSame(one, c.call()); } @@ -541,7 +554,7 @@ public class ExecutorsTest extends JSR16 * callable(PrivilegedExceptionAction) returns its result when called */ public void testCallable4() throws Exception { - Callable c = Executors.callable(new PrivilegedExceptionAction() { + Callable c = Executors.callable(new PrivilegedExceptionAction() { public Object run() { return one; }}); assertSame(one, c.call()); } @@ -551,7 +564,7 @@ public class ExecutorsTest extends JSR16 */ public void testCallableNPE1() { try { - Callable c = Executors.callable((Runnable) null); + Callable unused = Executors.callable((Runnable) null); shouldThrow(); } catch (NullPointerException success) {} } @@ -561,7 +574,7 @@ public class ExecutorsTest extends JSR16 */ public void testCallableNPE2() { try { - Callable c = Executors.callable((Runnable) null, one); + Callable unused = Executors.callable((Runnable) null, one); shouldThrow(); } catch (NullPointerException success) {} } @@ -571,7 +584,7 @@ public class ExecutorsTest extends JSR16 */ public void testCallableNPE3() { try { - Callable c = Executors.callable((PrivilegedAction) null); + Callable unused = Executors.callable((PrivilegedAction) null); shouldThrow(); } catch (NullPointerException success) {} } @@ -581,7 +594,7 @@ public class ExecutorsTest extends JSR16 */ public void testCallableNPE4() { try { - Callable c = Executors.callable((PrivilegedExceptionAction) null); + Callable unused = Executors.callable((PrivilegedExceptionAction) null); shouldThrow(); } catch (NullPointerException success) {} } @@ -615,6 +628,7 @@ public class ExecutorsTest extends JSR16 /** * privilegedCallable(callable).toString() contains toString of wrapped task */ + @SuppressWarnings("removal") public void testPrivilegedCallable_toString() { if (testImplementationDetails) { Callable c = () -> ""; @@ -629,6 +643,7 @@ public class ExecutorsTest extends JSR16 * privilegedCallableUsingCurrentClassLoader(callable).toString() * contains toString of wrapped task */ + @SuppressWarnings("removal") public void testPrivilegedCallableUsingCurrentClassLoader_toString() { if (testImplementationDetails) { Callable c = () -> "";