Disable the GoogleTestSecurityManager by default
and explicitly enable it for tests that rely on it.
The SecurityManager is being permanently disabled in JDK 24, see https://openjdk.org/jeps/486
PiperOrigin-RevId: 696974212
Change-Id: I425c0bb66e0c1c057129712e45b60ba481971db8
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
index 21bd785..8d2b883 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
@@ -90,7 +90,7 @@
return false; // Don't install over the specified security manager
}
return Boolean.valueOf(
- systemProperties.getProperty(SHOULD_INSTALL_SECURITY_MANAGER_PROPERTY, "true"));
+ systemProperties.getProperty(SHOULD_INSTALL_SECURITY_MANAGER_PROPERTY, "false"));
}
/**
diff --git a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4ConfigTest.java b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4ConfigTest.java
index 8357ea3e..f7e8ede 100644
--- a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4ConfigTest.java
+++ b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4ConfigTest.java
@@ -85,7 +85,7 @@
GoogleTestSecurityManager.uninstallIfInstalled();
JUnit4Config config = createConfigWithProperties(new Properties());
- assertThat(config.shouldInstallSecurityManager()).isTrue();
+ assertThat(config.shouldInstallSecurityManager()).isFalse();
}
@Test
diff --git a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4RunnerTest.java b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4RunnerTest.java
index e82c27d..dcdd3f9 100644
--- a/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4RunnerTest.java
+++ b/src/java_tools/junitrunner/javatests/com/google/testing/junit/runner/junit4/JUnit4RunnerTest.java
@@ -444,8 +444,8 @@
String apiVersion, boolean shouldInstallSecurityManager) {
Properties properties = new Properties();
properties.setProperty(JUnit4Config.JUNIT_API_VERSION_PROPERTY, apiVersion);
- if (!shouldInstallSecurityManager) {
- properties.setProperty("java.security.manager", "whatever");
+ if (shouldInstallSecurityManager) {
+ properties.setProperty(JUnit4Config.SHOULD_INSTALL_SECURITY_MANAGER_PROPERTY, "true");
}
return properties;
}