--- jsr166/src/test/tck/JSR166TestCase.java 2021/01/26 13:33:06 1.272 +++ jsr166/src/test/tck/JSR166TestCase.java 2022/11/25 16:39:49 1.276 @@ -152,7 +152,7 @@ import junit.framework.TestSuite; * in one spot to rerun tests on slower platforms. * * Class Item is used for elements of collections and related - * purposes. Many tests rely on themir keys being equal to ints. To + * purposes. Many tests rely on their keys being equal to ints. To * check these, methods mustEqual, mustContain, etc adapt the JUnit * assert methods to intercept ints. * @@ -195,8 +195,9 @@ import junit.framework.TestSuite; * */ public class JSR166TestCase extends TestCase { + // No longer run with custom securityManagers private static final boolean useSecurityManager = - Boolean.getBoolean("jsr166.useSecurityManager"); + Boolean.getBoolean("jsr166.useSecurityManager"); protected static final boolean expensiveTests = Boolean.getBoolean("jsr166.expensiveTests"); @@ -407,11 +408,15 @@ public class JSR166TestCase extends Test * Runs all unit tests in the given test suite. * Actual behavior influenced by jsr166.* system properties. */ + @SuppressWarnings("removal") static void main(Test suite, String[] args) { if (useSecurityManager) { System.err.println("Setting a permissive security manager"); Policy.setPolicy(permissivePolicy()); - System.setSecurityManager(new SecurityManager()); + try { + System.setSecurityManager(new SecurityManager()); + } catch (Throwable ok) { // failure OK during deprecation + } } for (int i = 0; i < suiteRuns; i++) { TestResult result = newPithyTestRunner().doRun(suite); @@ -452,14 +457,18 @@ public class JSR166TestCase extends Test public static final String JAVA_SPECIFICATION_VERSION; static { try { - JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged( + @SuppressWarnings("removal") double jcv = + java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Double run() { return Double.valueOf(System.getProperty("java.class.version"));}}); - JAVA_SPECIFICATION_VERSION = java.security.AccessController.doPrivileged( + JAVA_CLASS_VERSION = jcv; + @SuppressWarnings("removal") String jsv = + java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public String run() { return System.getProperty("java.specification.version");}}); + JAVA_SPECIFICATION_VERSION = jsv; } catch (Throwable t) { throw new Error(t); } @@ -596,6 +605,12 @@ public class JSR166TestCase extends Test addNamedTestClasses(suite, java9TestClassNames); } + if (atLeastJava17()) { + String[] java17TestClassNames = { + "ForkJoinPool19Test", + }; + addNamedTestClasses(suite, java17TestClassNames); + } return suite; } @@ -1054,7 +1069,7 @@ public class JSR166TestCase extends Test void joinPool(ExecutorService pool) { try { pool.shutdown(); - if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) { + if (!pool.awaitTermination(20 * LONG_DELAY_MS, MILLISECONDS)) { try { threadFail("ExecutorService " + pool + " did not terminate in a timely manner"); @@ -1138,6 +1153,7 @@ public class JSR166TestCase extends Test * A debugging tool to print stack traces of most threads, as jstack does. * Uninteresting threads are filtered out. */ + @SuppressWarnings("removal") static void dumpTestThreads() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -1346,9 +1362,7 @@ public class JSR166TestCase extends Test assertTrue(c.remove(i)); } static void mustNotRemove(Collection c, int i) { - Item[] items = defaultItems; - Item x = (i >= 0 && i < items.length) ? items[i] : new Item(i); - assertFalse(c.remove(x)); + assertFalse(c.remove(itemFor(i))); } static void mustNotRemove(Collection c, Item i) { assertFalse(c.remove(i)); @@ -1373,6 +1387,7 @@ public class JSR166TestCase extends Test * security manager. We require that any security manager permit * getPolicy/setPolicy. */ + @SuppressWarnings("removal") public void runWithPermissions(Runnable r, Permission... permissions) { SecurityManager sm = System.getSecurityManager(); if (sm == null) { @@ -1388,8 +1403,10 @@ public class JSR166TestCase extends Test * Runnable. We require that any security manager permit * getPolicy/setPolicy. */ + @SuppressWarnings("removal") public void runWithSecurityManagerWithPermissions(Runnable r, Permission... permissions) { + if (!useSecurityManager) return; SecurityManager sm = System.getSecurityManager(); if (sm == null) { Policy savedPolicy = Policy.getPolicy(); @@ -1397,9 +1414,13 @@ public class JSR166TestCase extends Test Policy.setPolicy(permissivePolicy()); System.setSecurityManager(new SecurityManager()); runWithSecurityManagerWithPermissions(r, permissions); + } catch (UnsupportedOperationException ok) { } finally { - System.setSecurityManager(null); - Policy.setPolicy(savedPolicy); + try { + System.setSecurityManager(null); + Policy.setPolicy(savedPolicy); + } catch (Exception ok) { + } } } else { Policy savedPolicy = Policy.getPolicy(); @@ -1426,6 +1447,7 @@ public class JSR166TestCase extends Test * A security policy where new permissions can be dynamically added * or all cleared. */ + @SuppressWarnings("removal") public static class AdjustablePolicy extends java.security.Policy { Permissions perms = new Permissions(); AdjustablePolicy(Permission... permissions) { @@ -1455,6 +1477,7 @@ public class JSR166TestCase extends Test /** * Returns a policy containing all the permissions we ever need. */ + @SuppressWarnings("removal") public static Policy permissivePolicy() { return new AdjustablePolicy // Permissions j.u.c. needs directly