System.exit()
should only be invoked within application entry points JAVA-W0060System.exit
should only be used in entrypoint methods107 // download the latest version and run it
108 downloadLatestVersion();
109 launchNewVersion(latestVersion);
110 System.exit(0);111 }
112 } else {
113 logger.info("Running latest version");
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.
if (input == null) System.exit(1);
Consider throwing an exception on failure instead.
if (input == null) throw new InvalidInputException();
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.