Java

Java

Made by DeepSource

System.exit() should only be invoked within application entry points JAVA-S0060

Bug risk
Major

This method invokes System.exit(), and is called by other code. This can prevent proper error handling and debugging.

Invoking System.exit() shuts down the entire Java virtual machine. This should only been done when it is appropriate. Such calls make it hard or impossible for your code to be invoked by other code, since an error that causes System.exit() to be invoked cannot be handled by the calling code at all.

Examples

Problematic Code

if (input == null) System.exit(1);

Recommended

Consider throwing an exception on failure instead.

if (input == null) throw new InvalidInputException();
   

Exceptions

If the code is intended to be called only by an application entrypoint, this issue can safely be ignored. Ensure that such cases are well documented.

References