System.exit
should only be used in entrypoint methods157 e.printStackTrace();
158 }
159
160 System.exit(0);161 });
162
163 return "Big success!";
System.exit
should only be used in entrypoint methods460 */
461 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
462 stopAll();
463 System.exit(0);464 }//GEN-LAST:event_formWindowClosing
465
466 /**
System.exit
should only be used in entrypoint methods12 public void run() {
13 try {
14 Thread.sleep(10000L);
15 System.exit(0);16 } catch (InterruptedException e) {
17 Log.log(e);
18 }
Description
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.
Bad Practice
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
- Spotbugs - DM_EXIT