Skip to content

Commit

Permalink
No longer prevent System.exit() by default (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhoeben authored Oct 20, 2024
1 parent 7bed6ad commit 994e604
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions FitNesseRoot/FitNesse/ReleaseNotes/content.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static boolean isPreventSystemExit() {
if (preventSystemExitString != null) {
return Boolean.parseBoolean(preventSystemExitString);
} else {
return true;
return false;
}
}

Expand Down
21 changes: 7 additions & 14 deletions test/fitnesse/slim/instructions/SystemExitSecurityManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
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();
}

@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();
Expand Down

0 comments on commit 994e604

Please sign in to comment.