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