I have an interactive Java program that allows a user to send messages to a server that behaves like a shell, accepts user keyboard input, and performs various actions.
for instance
myProgram> send "Login as James" to server
My program will analyze the user’s input and take an action, in which case he will send the message “Login as James” to the server.
One of the commands that I support in my "quit", which will close all connections to the server, clear resources and turn off the application. and the code to process this quit command:
private void shutdown()
{
closeAllConnection();
cleanup();
System.out.println("Thank you for using the tool, have a nice day!");
System.exit(0);
}
When I run findbug against my code, a DM_EXIT error appears
Bug: new myProgram.messagingTools.main(String[]) invokes System.exit(...), which shuts down the entire virtual machine
Pattern id: DM_EXIT, type: Dm, category: BAD_PRACTICE
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. Consider throwing a RuntimeException instead.
and he complains that System.exit should not be used to shut down the program.
- , " , " quit "??