Java 25 Removes SecurityManager: What to Fix
Resumo
Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing specific exceptions, and using separate processes or containers to isolate untrusted code. Search for SecurityManager, checkPermission, checkExit, and the java.security.manager flag before upgrading.
DEV Community
Your Tests Blocked System.exit With a SecurityManager and Java 25 Will Not Let You Install One
The command line tool called System.exit when its arguments were wrong. Fine in production. Fatal in a test. One call and the whole test run just stopped. Years ago somebody solved it. A small SecurityManager, installed in the tests, that threw an exception whenever code tried to exit. The test caught the exception, checked the exit code, and carried on. Plenty of teams did the same. Libraries were written for it. Plugin hosts did something similar, sandboxing code they loaded. You have probably got one of these somewhere and forgotten it. The Security Manager was deprecated for removal in Java 17. You saw the warning. So did everyone. In Java 24, JEP 486 switched it off for good. You cannot enable it at startup. You cannot install one while the program runs. System.setSecurityManager now throws UnsupportedOperationException. Java 25 is the long term release that most teams on 21 are moving to now. So for many codebases this is not a future warning. It is the next upgrade, failing in the test suite on day one. Usually in a helper class nobody has opened in years. The good news is that the real fix was always the better design. Do not call System.exit deep inside your code. Return an exit code, or throw a specific exception, and let main be the only place that ends the process. Then the tests call the logic, not main, and check the code it returned. No trick needed. If you load code you do not trust, the answer is no longer inside the same JVM. Run it in a separate process or a container, with the operating system drawing the limits. The JDK team's position is that the Security Manager was rarely used for that anyway, and expensive to keep. Before you upgrade, search for it. SecurityManager. checkPermission. checkExit. The java.security.manager flag in your build files. Count the hits. That is the size of the work hiding behind a deprecation warning you stopped reading five years ago. A warning that says for removal is a date, not an opinion. – Serguey Asael Shinder

Powered by Readybot.io