Rule Definition
Using 'java.System.exit()' is prohibited since it goes against the Exception error handling model.
Remediation
Don't use 'java.System.exit()', 'Runtime.getRuntime().exit(0)' and 'Runtime.getRuntime().halt(0)' to know what happened when you exit your program
Violation Code Sample
sample #1 public class KO_UseExit { { if (System.currentTimeMillis() >500000) System.exit(0); } public KO_UseExit() { System.exit(0); } public void ko_go() { System.exit(0); } } ------------------------------------------------- sample # 2 public class KO_UseExit { { if (System.currentTimeMillis() >500000) Runtime.getRuntime().exit(0); } public KO_UseExit() { Runtime.getRuntime().exit(0); } public void ko_go() { Runtime.getRuntime().exit(0); } } -------------------------------------------------------- sample # 3 public class KO_UseExit { { if (System.currentTimeMillis() >500000) Runtime.getRuntime().halt(0) public KO_UseExit() { Runtime.getRuntime().halt(0) } public void ko_go() { Runtime.getRuntime().halt(0) } }
Fixed Code Sample
public class ok_UseExit { { if (System.currentTimeMillis() >500000) return; } public OK_UseExit() { return; } public void ok_go() { return; } }
Reference
http://cwe.mitre.org/data/definitions/382.html https://wiki.sei.cmu.edu/confluence/display/java/ERR09-J.+Do+not+allow+untrusted+code+to+terminate+the+JVM https://javarevisited.blogspot.com/2014/11/dont-use-systemexit-on-java-web-application.html https://www.baeldung.com/java-system-exit https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
Related Technologies
JEE
Technical Criterion
Secure Coding - Weak Security Features
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.