我有一个交互式java程序,允许用户将消息发送到服务器,服务器的行为类似于shell,接受用户的键盘输入并执行各种操作.
例如
myProgram> send "Login as James" to server
Run Code Online (Sandbox Code Playgroud)
我的程序将解析用户输入并执行操作,在这种情况下,它将向服务器发送消息"Login as James".
我支持其"退出"的命令之一,它将关闭所有服务器连接,清理资源并关闭应用程序.以及处理此退出命令的代码是
private void shutdown()
{
closeAllConnection();
cleanup();
System.out.println("Thank you for using the tool, have a nice day!");
System.exit(0);
}
Run Code Online (Sandbox Code Playgroud)
当我对我的代码运行findbug时,会引发DM_EXIT错误
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 …Run Code Online (Sandbox Code Playgroud)