63 |
|
*/ |
64 |
|
public void testNewCachedThreadPool3() { |
65 |
|
try { |
66 |
< |
ExecutorService e = Executors.newCachedThreadPool(null); |
66 |
> |
ExecutorService unused = Executors.newCachedThreadPool(null); |
67 |
|
shouldThrow(); |
68 |
|
} catch (NullPointerException success) {} |
69 |
|
} |
97 |
|
*/ |
98 |
|
public void testNewSingleThreadExecutor3() { |
99 |
|
try { |
100 |
< |
ExecutorService e = Executors.newSingleThreadExecutor(null); |
100 |
> |
ExecutorService unused = Executors.newSingleThreadExecutor(null); |
101 |
|
shouldThrow(); |
102 |
|
} catch (NullPointerException success) {} |
103 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
/** |
143 |
< |
* A new newFixedThreadPool with null ThreadFactory throws NPE |
143 |
> |
* A new newFixedThreadPool with null ThreadFactory throws |
144 |
> |
* NullPointerException |
145 |
|
*/ |
146 |
|
public void testNewFixedThreadPool3() { |
147 |
|
try { |
148 |
< |
ExecutorService e = Executors.newFixedThreadPool(2, null); |
148 |
> |
ExecutorService unused = Executors.newFixedThreadPool(2, null); |
149 |
|
shouldThrow(); |
150 |
|
} catch (NullPointerException success) {} |
151 |
|
} |
152 |
|
|
153 |
|
/** |
154 |
< |
* A new newFixedThreadPool with 0 threads throws IAE |
154 |
> |
* A new newFixedThreadPool with 0 threads throws IllegalArgumentException |
155 |
|
*/ |
156 |
|
public void testNewFixedThreadPool4() { |
157 |
|
try { |
158 |
< |
ExecutorService e = Executors.newFixedThreadPool(0); |
158 |
> |
ExecutorService unused = Executors.newFixedThreadPool(0); |
159 |
|
shouldThrow(); |
160 |
|
} catch (IllegalArgumentException success) {} |
161 |
|
} |
177 |
|
*/ |
178 |
|
public void testUnconfigurableExecutorServiceNPE() { |
179 |
|
try { |
180 |
< |
ExecutorService e = Executors.unconfigurableExecutorService(null); |
180 |
> |
ExecutorService unused = |
181 |
> |
Executors.unconfigurableExecutorService(null); |
182 |
|
shouldThrow(); |
183 |
|
} catch (NullPointerException success) {} |
184 |
|
} |
188 |
|
*/ |
189 |
|
public void testUnconfigurableScheduledExecutorServiceNPE() { |
190 |
|
try { |
191 |
< |
ExecutorService e = Executors.unconfigurableScheduledExecutorService(null); |
191 |
> |
ExecutorService unused = |
192 |
> |
Executors.unconfigurableScheduledExecutorService(null); |
193 |
|
shouldThrow(); |
194 |
|
} catch (NullPointerException success) {} |
195 |
|
} |
284 |
|
delay(LONG_DELAY_MS); |
285 |
|
}}; |
286 |
|
|
287 |
< |
List<Thread> threads = new ArrayList<Thread>(); |
287 |
> |
List<Thread> threads = new ArrayList<>(); |
288 |
|
for (final ExecutorService executor : executors) { |
289 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
290 |
|
public void realRun() { |
309 |
|
public void realRun() { |
310 |
|
try { |
311 |
|
Thread current = Thread.currentThread(); |
312 |
< |
assertTrue(!current.isDaemon()); |
312 |
> |
assertFalse(current.isDaemon()); |
313 |
|
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
311 |
– |
ThreadGroup g = current.getThreadGroup(); |
314 |
|
SecurityManager s = System.getSecurityManager(); |
315 |
< |
if (s != null) |
316 |
< |
assertTrue(g == s.getThreadGroup()); |
317 |
< |
else |
316 |
< |
assertTrue(g == egroup); |
317 |
< |
String name = current.getName(); |
318 |
< |
assertTrue(name.endsWith("thread-1")); |
315 |
> |
assertSame(current.getThreadGroup(), |
316 |
> |
(s == null) ? egroup : s.getThreadGroup()); |
317 |
> |
assertTrue(current.getName().endsWith("thread-1")); |
318 |
|
} catch (SecurityException ok) { |
319 |
|
// Also pass if not allowed to change setting |
320 |
|
} |
342 |
|
Runnable r = new CheckedRunnable() { |
343 |
|
public void realRun() { |
344 |
|
Thread current = Thread.currentThread(); |
345 |
< |
assertTrue(!current.isDaemon()); |
345 |
> |
assertFalse(current.isDaemon()); |
346 |
|
assertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
348 |
– |
ThreadGroup g = current.getThreadGroup(); |
347 |
|
SecurityManager s = System.getSecurityManager(); |
348 |
< |
if (s != null) |
349 |
< |
assertTrue(g == s.getThreadGroup()); |
350 |
< |
else |
353 |
< |
assertTrue(g == egroup); |
354 |
< |
String name = current.getName(); |
355 |
< |
assertTrue(name.endsWith("thread-1")); |
348 |
> |
assertSame(current.getThreadGroup(), |
349 |
> |
(s == null) ? egroup : s.getThreadGroup()); |
350 |
> |
assertTrue(current.getName().endsWith("thread-1")); |
351 |
|
assertSame(thisccl, current.getContextClassLoader()); |
352 |
|
assertEquals(thisacc, AccessController.getContext()); |
353 |
|
done.countDown(); |
553 |
|
*/ |
554 |
|
public void testCallableNPE1() { |
555 |
|
try { |
556 |
< |
Callable c = Executors.callable((Runnable) null); |
556 |
> |
Callable unused = Executors.callable((Runnable) null); |
557 |
|
shouldThrow(); |
558 |
|
} catch (NullPointerException success) {} |
559 |
|
} |
563 |
|
*/ |
564 |
|
public void testCallableNPE2() { |
565 |
|
try { |
566 |
< |
Callable c = Executors.callable((Runnable) null, one); |
566 |
> |
Callable unused = Executors.callable((Runnable) null, one); |
567 |
|
shouldThrow(); |
568 |
|
} catch (NullPointerException success) {} |
569 |
|
} |
573 |
|
*/ |
574 |
|
public void testCallableNPE3() { |
575 |
|
try { |
576 |
< |
Callable c = Executors.callable((PrivilegedAction) null); |
576 |
> |
Callable unused = Executors.callable((PrivilegedAction) null); |
577 |
|
shouldThrow(); |
578 |
|
} catch (NullPointerException success) {} |
579 |
|
} |
583 |
|
*/ |
584 |
|
public void testCallableNPE4() { |
585 |
|
try { |
586 |
< |
Callable c = Executors.callable((PrivilegedExceptionAction) null); |
586 |
> |
Callable unused = Executors.callable((PrivilegedExceptionAction) null); |
587 |
|
shouldThrow(); |
588 |
|
} catch (NullPointerException success) {} |
589 |
|
} |
590 |
|
|
591 |
+ |
/** |
592 |
+ |
* callable(runnable, x).toString() contains toString of wrapped task |
593 |
+ |
*/ |
594 |
+ |
public void testCallable_withResult_toString() { |
595 |
+ |
if (testImplementationDetails) { |
596 |
+ |
Runnable r = () -> {}; |
597 |
+ |
Callable<String> c = Executors.callable(r, ""); |
598 |
+ |
assertEquals( |
599 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
600 |
+ |
c.toString()); |
601 |
+ |
} |
602 |
+ |
} |
603 |
+ |
|
604 |
+ |
/** |
605 |
+ |
* callable(runnable).toString() contains toString of wrapped task |
606 |
+ |
*/ |
607 |
+ |
public void testCallable_toString() { |
608 |
+ |
if (testImplementationDetails) { |
609 |
+ |
Runnable r = () -> {}; |
610 |
+ |
Callable<Object> c = Executors.callable(r); |
611 |
+ |
assertEquals( |
612 |
+ |
identityString(c) + "[Wrapped task = " + r.toString() + "]", |
613 |
+ |
c.toString()); |
614 |
+ |
} |
615 |
+ |
} |
616 |
+ |
|
617 |
+ |
/** |
618 |
+ |
* privilegedCallable(callable).toString() contains toString of wrapped task |
619 |
+ |
*/ |
620 |
+ |
public void testPrivilegedCallable_toString() { |
621 |
+ |
if (testImplementationDetails) { |
622 |
+ |
Callable<String> c = () -> ""; |
623 |
+ |
Callable<String> priv = Executors.privilegedCallable(c); |
624 |
+ |
assertEquals( |
625 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
626 |
+ |
priv.toString()); |
627 |
+ |
} |
628 |
+ |
} |
629 |
+ |
|
630 |
+ |
/** |
631 |
+ |
* privilegedCallableUsingCurrentClassLoader(callable).toString() |
632 |
+ |
* contains toString of wrapped task |
633 |
+ |
*/ |
634 |
+ |
public void testPrivilegedCallableUsingCurrentClassLoader_toString() { |
635 |
+ |
if (testImplementationDetails) { |
636 |
+ |
Callable<String> c = () -> ""; |
637 |
+ |
Callable<String> priv = Executors.privilegedCallableUsingCurrentClassLoader(c); |
638 |
+ |
assertEquals( |
639 |
+ |
identityString(priv) + "[Wrapped task = " + c.toString() + "]", |
640 |
+ |
priv.toString()); |
641 |
+ |
} |
642 |
+ |
} |
643 |
|
} |