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.15 by dl, Thu Jan 22 14:07:50 2004 UTC vs.
Revision 1.16 by dl, Tue Jan 27 11:37:00 2004 UTC

# 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 488 | Line 500 | public class ExecutorsTest extends JSR16
500          }
501      }
502  
491    class CallCCL implements Runnable {
492        final Callable task;
493        CallCCL(Callable t) { task = t; }
494        public void run() {
495            try {
496                task.call();
497                threadShouldThrow();
498            } catch(AccessControlException success) {
499            } catch(Exception ex) {
500                threadUnexpectedException();
501            }
502        }
503    }
504
503      /**
504       * Without permissions, calling privilegedCallable throws ACE
505       */
506      public void testprivilegedCallableWithNoPrivs() {
507 <        Thread t1;
507 >        Callable task;
508 >        Policy savedPolicy = null;
509 >        AdjustablePolicy policy = null;
510 >        AccessControlContext noprivAcc = null;
511          try {
512 <            Policy savedPolicy = Policy.getPolicy();
513 <            AdjustablePolicy policy = new AdjustablePolicy();
512 >            savedPolicy = Policy.getPolicy();
513 >            policy = new AdjustablePolicy();
514              Policy.setPolicy(policy);
515 <            Callable task = Executors.privilegedCallable(new CheckCCL());
516 <            t1 = new Thread(new CallCCL(task));
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  
534          try {
535 <            t1.start();
536 <            t1.join();
535 >            task.call();
536 >            shouldThrow();
537 >        } catch(AccessControlException success) {
538          } catch(Exception ex) {
539              unexpectedException();
540          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines