From 994e604d91f6418615e716a40bad317ca22f4fc1 Mon Sep 17 00:00:00 2001 From: Fried Hoeben Date: Sun, 20 Oct 2024 15:36:24 +0200 Subject: [PATCH] No longer prevent `System.exit()` by default (#1524) --- .../FitNesse/ReleaseNotes/content.txt | 1 + .../SystemExitIsPrevented/content.txt | 2 ++ .../SystemExitSecurityManager.java | 2 +- .../SystemExitSecurityManagerTest.java | 21 +++++++------------ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt index 5493e4804e..251a87b2ed 100644 --- a/FitNesseRoot/FitNesse/ReleaseNotes/content.txt +++ b/FitNesseRoot/FitNesse/ReleaseNotes/content.txt @@ -1,4 +1,5 @@ !2 Pending Changes + * IMPORTANT: !style_code[System.exit()] is no longer prevented by default ([[1524][https://github.com/unclebob/fitnesse/pull/1524]]). * Fix SLF4J logging ([[1522][https://github.com/unclebob/fitnesse/pull/1522]]) !2 20240707 diff --git a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/SystemExitIsPrevented/content.txt b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/SystemExitIsPrevented/content.txt index 6f3c2c8bd4..4aca8a0235 100644 --- a/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/SystemExitIsPrevented/content.txt +++ b/FitNesseRoot/FitNesse/SuiteAcceptanceTests/SuiteSlimTests/SystemExitIsPrevented/content.txt @@ -1,3 +1,5 @@ +This test should be removed or 'pruned' when running on Java 21 or higher, as preventing system exit is no longer supported there. + !|script|SystemExitTableConfiguration | |set system property|prevent.system.exit|to|true| diff --git a/src/fitnesse/slim/instructions/SystemExitSecurityManager.java b/src/fitnesse/slim/instructions/SystemExitSecurityManager.java index 94871ee105..1f11c00562 100644 --- a/src/fitnesse/slim/instructions/SystemExitSecurityManager.java +++ b/src/fitnesse/slim/instructions/SystemExitSecurityManager.java @@ -54,7 +54,7 @@ private static boolean isPreventSystemExit() { if (preventSystemExitString != null) { return Boolean.parseBoolean(preventSystemExitString); } else { - return true; + return false; } } diff --git a/test/fitnesse/slim/instructions/SystemExitSecurityManagerTest.java b/test/fitnesse/slim/instructions/SystemExitSecurityManagerTest.java index f8de062676..3a3524a247 100644 --- a/test/fitnesse/slim/instructions/SystemExitSecurityManagerTest.java +++ b/test/fitnesse/slim/instructions/SystemExitSecurityManagerTest.java @@ -1,19 +1,13 @@ package fitnesse.slim.instructions; -import static org.junit.Assert.fail; -import static util.RegexTestCase.assertMatches; - +import fitnesse.slim.instructions.SystemExitSecurityManager.SystemExitException; import org.junit.After; import org.junit.Test; -import fitnesse.slim.instructions.SystemExitSecurityManager.SystemExitException; +import static org.junit.Assert.fail; +import static util.RegexTestCase.assertMatches; public class SystemExitSecurityManagerTest { - - SecurityManager oldSecurityManager; - - SecurityManager securityManager; - @After public void teardown() { SystemExitSecurityManager.restoreOriginalSecurityManager(); @@ -21,24 +15,23 @@ public void teardown() { @Test(expected = SystemExitException.class) public void shouldThrowExceptionWhenSystemExitIsCalled() { - acticateSystemExitSecurityManager(); + activateSystemExitSecurityManager(); System.exit(0); fail("should have thrown exception"); - } @Test public void shouldIncludeExitCode() { try { - acticateSystemExitSecurityManager(); + activateSystemExitSecurityManager(); System.exit(42); fail("should have thrown exception"); } catch (SystemExitException e) { assertMatches("system exit with exit code 42", e.getMessage()); } } - - private void acticateSystemExitSecurityManager() { + + private void activateSystemExitSecurityManager() { System.setSecurityManager(null); System.setProperty(SystemExitSecurityManager.PREVENT_SYSTEM_EXIT, "true"); SystemExitSecurityManager.activateIfWanted();