--- jsr166/src/test/tck/ForkJoinPoolTest.java 2010/11/18 19:14:34 1.34 +++ jsr166/src/test/tck/ForkJoinPoolTest.java 2010/11/19 00:20:47 1.35 @@ -428,106 +428,63 @@ public class ForkJoinPoolTest extends JS } } - /** * A submitted privileged action runs to completion */ - public void testSubmitPrivilegedAction() throws Throwable { - Policy savedPolicy = null; - try { - savedPolicy = Policy.getPolicy(); - AdjustablePolicy policy = new AdjustablePolicy(); - policy.addPermission(new RuntimePermission("getContextClassLoader")); - policy.addPermission(new RuntimePermission("setContextClassLoader")); - Policy.setPolicy(policy); - } catch (AccessControlException ok) { - return; - } - - try { - ExecutorService e = new ForkJoinPool(1); - try { + public void testSubmitPrivilegedAction() throws Exception { + Runnable r = new CheckedRunnable() { + public void realRun() throws Exception { + ExecutorService e = new ForkJoinPool(1); Future future = e.submit(Executors.callable(new PrivilegedAction() { public Object run() { return TEST_STRING; }})); - Object result = future.get(); - assertSame(TEST_STRING, result); - } finally { - joinPool(e); - } - } finally { - Policy.setPolicy(savedPolicy); - } + assertSame(TEST_STRING, future.get()); + }}; + + runWithPermissions(r, + new RuntimePermission("modifyThread")); } /** * A submitted privileged exception action runs to completion */ - public void testSubmitPrivilegedExceptionAction() throws Throwable { - Policy savedPolicy = null; - try { - savedPolicy = Policy.getPolicy(); - AdjustablePolicy policy = new AdjustablePolicy(); - policy.addPermission(new RuntimePermission("getContextClassLoader")); - policy.addPermission(new RuntimePermission("setContextClassLoader")); - Policy.setPolicy(policy); - } catch (AccessControlException ok) { - return; - } - - try { - ExecutorService e = new ForkJoinPool(1); - try { + public void testSubmitPrivilegedExceptionAction() throws Exception { + Runnable r = new CheckedRunnable() { + public void realRun() throws Exception { + ExecutorService e = new ForkJoinPool(1); Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { public Object run() { return TEST_STRING; }})); - Object result = future.get(); - assertSame(TEST_STRING, result); - } finally { - joinPool(e); - } - } finally { - Policy.setPolicy(savedPolicy); - } + assertSame(TEST_STRING, future.get()); + }}; + + runWithPermissions(r, new RuntimePermission("modifyThread")); } /** * A submitted failed privileged exception action reports exception */ - public void testSubmitFailedPrivilegedExceptionAction() throws Throwable { - Policy savedPolicy = null; - try { - savedPolicy = Policy.getPolicy(); - AdjustablePolicy policy = new AdjustablePolicy(); - policy.addPermission(new RuntimePermission("getContextClassLoader")); - policy.addPermission(new RuntimePermission("setContextClassLoader")); - Policy.setPolicy(policy); - } catch (AccessControlException ok) { - return; - } - - try { - ExecutorService e = new ForkJoinPool(1); - try { + public void testSubmitFailedPrivilegedExceptionAction() throws Exception { + Runnable r = new CheckedRunnable() { + public void realRun() throws Exception { + ExecutorService e = new ForkJoinPool(1); Future future = e.submit(Executors.callable(new PrivilegedExceptionAction() { public Object run() throws Exception { throw new IndexOutOfBoundsException(); }})); - Object result = future.get(); - shouldThrow(); - } catch (ExecutionException success) { - assertTrue(success.getCause() instanceof IndexOutOfBoundsException); - } finally { - joinPool(e); - } - } finally { - Policy.setPolicy(savedPolicy); - } + try { + future.get(); + shouldThrow(); + } catch (ExecutionException success) { + assertTrue(success.getCause() instanceof IndexOutOfBoundsException); + }}}; + + runWithPermissions(r, new RuntimePermission("modifyThread")); } /**