[cvs] / jsr166 / src / test / tck / FutureTaskTest.java Repository:
ViewVC logotype

Diff of /jsr166/src/test/tck/FutureTaskTest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.32, Sun Dec 16 18:52:27 2012 UTC revision 1.33, Thu Dec 20 04:58:53 2012 UTC
# Line 406  Line 406 
406      }      }
407    
408      /**      /**
409       * cancel(true) interrupts a running task that subsequently       * cancel(true) tries to interrupt a running task, but
410       * succeeds, with a security manager that does not permit       * Thread.interrupt throws (simulating a restrictive security
411       * Thread.interrupt       * manager)
412       */       */
413      public void testCancelInterrupt_ThrowsSecurityException() {      public void testCancelInterrupt_ThrowsSecurityException() {
         if (System.getSecurityManager() != null)  
             return;  
   
414          final CountDownLatch pleaseCancel = new CountDownLatch(1);          final CountDownLatch pleaseCancel = new CountDownLatch(1);
415          final CountDownLatch cancelled = new CountDownLatch(1);          final CountDownLatch cancelled = new CountDownLatch(1);
416          final PublicFutureTask task =          final PublicFutureTask task =
# Line 424  Line 421 
421                      assertFalse(Thread.interrupted());                      assertFalse(Thread.interrupted());
422                  }});                  }});
423    
424          final Thread t = newStartedThread(task);          final Thread t = new Thread(task) {
425                // Simulate a restrictive security manager.
426                @Override public void interrupt() {
427                    throw new SecurityException();
428                }};
429            t.setDaemon(true);
430            t.start();
431    
432          await(pleaseCancel);          await(pleaseCancel);
         System.setSecurityManager(new SecurityManager() {  
             public void checkAccess(Thread t) { throw new SecurityException(); }  
             public void checkPermission(Permission p) {}});  
         try {  
433              try {              try {
434                  task.cancel(true);                  task.cancel(true);
435                  shouldThrow();                  shouldThrow();
436              }          } catch (SecurityException expected) {}
437              catch (SecurityException expected) {}  
438          } finally {          // We failed to deliver the interrupt, but the world retains
439              System.setSecurityManager(null);          // its sanity, as if we had done task.cancel(false)
         }  
440          assertTrue(task.isCancelled());          assertTrue(task.isCancelled());
441          assertTrue(task.isDone());          assertTrue(task.isDone());
442          assertEquals(1, task.runCount());          assertEquals(1, task.runCount());

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8