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.17 by dl, Mon Apr 3 15:00:59 2006 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 >            AccessController.getContext().checkPermission(new RuntimePermission("getContextClassLoader"));
431 >    }
432 >
433 >    class CheckCCL implements Callable<Object> {
434          public Object call() {
435 <            AccessControlContext acc = AccessController.getContext();
432 <            acc.checkPermission(new RuntimePermission("getContextClassLoader"));
435 >            checkCCL();
436              return null;
437          }
438      }
# Line 449 | Line 452 | public class ExecutorsTest extends JSR16
452              return;
453          }
454  
455 +        // Check if program still has too many permissions to run test
456 +        try {
457 +            checkCCL();
458 +            // too many privileges to test; so return
459 +            Policy.setPolicy(savedPolicy);
460 +            return;
461 +        } catch(AccessControlException ok) {
462 +        }
463 +
464          try {
465              Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable());
466              shouldThrow();
# Line 462 | Line 474 | public class ExecutorsTest extends JSR16
474      }
475  
476      /**
477 <     * Without class loader permissions, calling
478 <     * privilegedCallableUsingCurrentClassLoader throws ACE
477 >     * With class loader permissions, calling
478 >     * privilegedCallableUsingCurrentClassLoader does not throw ACE
479       */
480      public void testprivilegedCallableUsingCCLWithPrivs() {
481          Policy savedPolicy = null;
# Line 492 | Line 504 | public class ExecutorsTest extends JSR16
504       * Without permissions, calling privilegedCallable throws ACE
505       */
506      public void testprivilegedCallableWithNoPrivs() {
507 <        Policy savedPolicy = null;
507 >        Callable task;
508 >        Policy savedPolicy = null;
509 >        AdjustablePolicy policy = null;
510 >        AccessControlContext noprivAcc = null;
511          try {
512              savedPolicy = Policy.getPolicy();
513 <            AdjustablePolicy policy = new AdjustablePolicy();
513 >            policy = new AdjustablePolicy();
514              Policy.setPolicy(policy);
515 +            noprivAcc = AccessController.getContext();
516 +            task = Executors.privilegedCallable(new CheckCCL());
517 +            Policy.setPolicy(savedPolicy);
518          } catch (AccessControlException ok) {
519 +            return; // program has too few permissions to set up test
520 +        }
521 +
522 +        // Make sure that program doesn't have too many permissions
523 +        try {
524 +            AccessController.doPrivileged(new PrivilegedAction() {
525 +                    public Object run() {
526 +                        checkCCL();
527 +                        return null;
528 +                    }}, noprivAcc);
529 +            // too many permssions; skip test
530              return;
531 +        } catch(AccessControlException ok) {
532          }
533  
504        Callable task = Executors.privilegedCallable(new CheckCCL());
505        Policy.setPolicy(savedPolicy);
534          try {
535              task.call();
536              shouldThrow();
537          } catch(AccessControlException success) {
538          } catch(Exception ex) {
539              unexpectedException();
540 <        } finally {
513 <        }
540 >        }
541      }
542  
543      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines