The virtual machine is stopped outside a main method

tx0/java:process-exitstrictwarningsmell

What it finds

System.exit and Runtime.halt stop the whole virtual machine, including the threads and the code of every caller, which get no chance to finish or clean up. In a library or a server this takes down far more than the piece of code that called it.

Calls inside a method named main are left alone, since a program's entry point is where its exit status is decided.

From the rule's source, process_exit.rs.

Example from the rule's tests
class App {  public static void main(String[] args) {    System.exit(run() ? 0 : 1);  }   static boolean run() {    if (Boolean.getBoolean("fail")) {      System.exit(2);tx0 reports: this call stops the whole virtual machine    }    Runtime.getRuntime().halt(3);tx0 reports: this call stops the whole virtual machine    return true;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:process-exit" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:process-exit] reason="..."

tx0 explain tx0/java:process-exit shows the same in the terminal. Found a false positive? Report it.