21 lines
928 B
Plaintext
21 lines
928 B
Plaintext
![]() |
Calling <code>System.exit(int status)</code> or <code>Rutime.getRuntime().exit(int status)</code> calls the shutdown hooks and shuts downs the entire Java virtual machine. Calling <code>Runtime.getRuntime().halt(int)</code> does an immediate shutdown, without calling the shutdown hooks, and skipping finalization.
|
||
|
|
||
|
Each of these methods should be used with extreme care, and only when the intent is to stop the whole Java process. For instance, none of them should be called from applications running in a J2EE container.
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
System.exit(0);
|
||
|
Runtime.getRuntime().exit(0);
|
||
|
Runtime.getRuntime().halt(0);
|
||
|
----
|
||
|
|
||
|
== Exceptions
|
||
|
|
||
|
These methods are ignored inside <code>main</code>.
|
||
|
|
||
|
== See
|
||
|
|
||
|
* http://cwe.mitre.org/data/definitions/382.html[MITRE, CWE-382] - Use of System.exit()
|
||
|
* https://www.securecoding.cert.org/confluence/x/PoYbAQ[CERT, ERR09-J.] - Do not allow untrusted code to terminate the JVM
|