ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ExecutorsTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ExecutorsTest.java (file contents):
Revision 1.14 by dl, Tue Jan 20 20:20:56 2004 UTC vs.
Revision 1.19 by jsr166, Tue Aug 4 16:06:12 2009 UTC

# Line 337 | Line 337 | public class ExecutorsTest extends JSR16
337                      try {
338                          Thread current = Thread.currentThread();
339                          threadAssertTrue(!current.isDaemon());
340 <                        threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY);
340 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
341                          ThreadGroup g = current.getThreadGroup();
342                          SecurityManager s = System.getSecurityManager();
343                          if (s != null)
# Line 392 | Line 392 | public class ExecutorsTest extends JSR16
392                      try {
393                          Thread current = Thread.currentThread();
394                          threadAssertTrue(!current.isDaemon());
395 <                        threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY);
395 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
396                          ThreadGroup g = current.getThreadGroup();
397                          SecurityManager s = System.getSecurityManager();
398                          if (s != null)
# Line 426 | Line 426 | public class ExecutorsTest extends JSR16
426  
427      }
428  
429 <    static class CheckCCL implements Callable<Object> {
429 >    void checkCCL() {
430 >        SecurityManager sm = System.getSecurityManager();
431 >        if (sm != null) {
432 >            sm.checkPermission(new RuntimePermission("setContextClassLoader"));
433 >            sm.checkPermission(new RuntimePermission("getClassLoader"));
434 >        }
435 >    }
436 >
437 >    class CheckCCL implements Callable<Object> {
438          public Object call() {
439 <            AccessControlContext acc = AccessController.getContext();
432 <            acc.checkPermission(new RuntimePermission("getContextClassLoader"));
439 >            checkCCL();
440              return null;
441          }
442      }
# Line 449 | Line 456 | public class ExecutorsTest extends JSR16
456              return;
457          }
458  
459 +        // Check if program still has too many permissions to run test
460 +        try {
461 +            checkCCL();
462 +            // too many privileges to test; so return
463 +            Policy.setPolicy(savedPolicy);
464 +            return;
465 +        } catch(AccessControlException ok) {
466 +        }
467 +
468          try {
469              Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable());
470              shouldThrow();
# Line 462 | Line 478 | public class ExecutorsTest extends JSR16
478      }
479  
480      /**
481 <     * Without class loader permissions, calling
482 <     * privilegedCallableUsingCurrentClassLoader throws ACE
481 >     * With class loader permissions, calling
482 >     * privilegedCallableUsingCurrentClassLoader does not throw ACE
483       */
484      public void testprivilegedCallableUsingCCLWithPrivs() {
485          Policy savedPolicy = null;
# Line 492 | Line 508 | public class ExecutorsTest extends JSR16
508       * Without permissions, calling privilegedCallable throws ACE
509       */
510      public void testprivilegedCallableWithNoPrivs() {
511 <        Policy savedPolicy = null;
511 >        Callable task;
512 >        Policy savedPolicy = null;
513 >        AdjustablePolicy policy = null;
514 >        AccessControlContext noprivAcc = null;
515          try {
516              savedPolicy = Policy.getPolicy();
517 <            AdjustablePolicy policy = new AdjustablePolicy();
517 >            policy = new AdjustablePolicy();
518              Policy.setPolicy(policy);
519 +            noprivAcc = AccessController.getContext();
520 +            task = Executors.privilegedCallable(new CheckCCL());
521 +            Policy.setPolicy(savedPolicy);
522          } catch (AccessControlException ok) {
523 +            return; // program has too few permissions to set up test
524 +        }
525 +
526 +        // Make sure that program doesn't have too many permissions
527 +        try {
528 +            AccessController.doPrivileged(new PrivilegedAction() {
529 +                    public Object run() {
530 +                        checkCCL();
531 +                        return null;
532 +                    }}, noprivAcc);
533 +            // too many permssions; skip test
534              return;
535 +        } catch(AccessControlException ok) {
536          }
537  
504        Callable task = Executors.privilegedCallable(new CheckCCL());
505        Policy.setPolicy(savedPolicy);
538          try {
539              task.call();
540              shouldThrow();
541          } catch(AccessControlException success) {
542          } catch(Exception ex) {
543              unexpectedException();
544 <        } finally {
513 <        }
544 >        }
545      }
546  
547      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines