jixuan1989 commented on a change in pull request #25: Fix sonar
URL: https://github.com/apache/incubator-iotdb/pull/25#discussion_r250492078
 
 

 ##########
 File path: iotdb-cli/src/main/java/org/apache/iotdb/cli/client/Client.java
 ##########
 @@ -121,82 +120,54 @@ public static void main(String[] args) throws 
ClassNotFoundException {
       return;
     }
 
-    ConsoleReader reader = null;
-    try {
-      reader = new ConsoleReader();
+    try(ConsoleReader reader = new ConsoleReader()) {
       reader.setExpandEvents(false);
-      // for (Completer completer : getCommandCompleter()) {
-      // reader.addCompleter(completer);
-      // }
-      // ((CandidateListCompletionHandler) reader.getCompletionHandler())
-      // .setPrintSpaceAfterFullCompletion(false);
       String s;
-      try {
-        host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, 
host);
-        port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, 
port);
-        username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, 
true, null);
 
-        password = commandLine.getOptionValue(PASSWORD_ARGS);
-        if (password == null) {
-          password = reader.readLine("please input your password:", '\0');
-        }
-        try {
-          connection = (IoTDBConnection) DriverManager
-              .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + 
"/", username, password);
-          properties = connection.getServerProperties();
-          
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
-        } catch (SQLException e) {
-          System.out.println(String.format("%s> %s. Host is %s, port is %s.", 
IOTDB_CLI_PREFIX,
-              e.getMessage(), host, port));
-          return;
-        }
+      host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
+      port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
+      username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, 
true, null);
 
-      } catch (ArgsErrorException e) {
-        // System.out.println(TSFILEDB_CLI_PREFIX + ": " + e.getMessage());
-        return;
+      password = commandLine.getOptionValue(PASSWORD_ARGS);
+      if (password == null) {
+        password = reader.readLine("please input your password:", '\0');
       }
-
-      displayLogo(properties.getVersion());
-      System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
-
-      while (true) {
-        s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
-        if (s == null) {
-          continue;
-        } else {
-          String[] cmds = s.trim().split(";");
-          for (int i = 0; i < cmds.length; i++) {
-            String cmd = cmds[i];
-            if (cmd != null && !cmd.trim().equals("")) {
-              OperationResult result = handleInputInputCmd(cmd, connection);
-              switch (result) {
-                case RETURN_OPER:
-                  return;
-                case CONTINUE_OPER:
-                  continue;
-                default:
-                  break;
+      try (IoTDBConnection connection = (IoTDBConnection) 
DriverManager.getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", 
username, password)){
+        properties = connection.getServerProperties();
+        
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
+        displayLogo(properties.getVersion());
+        System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
+        while (true) {
+          s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
+          if (s != null) {
+            String[] cmds = s.trim().split(";");
+            for (int i = 0; i < cmds.length; i++) {
+              String cmd = cmds[i];
+              if (cmd != null && !cmd.trim().equals("")) {
+                OperationResult result = handleInputCmd(cmd, connection);
+                switch (result) {
+                  case RETURN_OPER:
+                    return;
+                  case CONTINUE_OPER:
+                    continue;
+                  default:
+                    break;
+                }
               }
             }
           }
         }
+      } catch (SQLException e) {
+        System.out.println(String.format("%s> %s Host is %s, port is %s.", 
IOTDB_CLI_PREFIX, e.getMessage(), host, port));
       }
-    } catch (Exception e) {
+    } catch(ArgsErrorException e){
+      System.out.println(IOTDB_CLI_PREFIX + "> input params error because" + 
e.getMessage());
+    }catch (Exception e) {
 
 Review comment:
   code checkstyle:
   } catch

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to