[Title] Fix sonar critical bug
authorho.namkoong <ho.namkoong@samsung.com>
Tue, 16 Apr 2013 07:36:12 +0000 (16:36 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Tue, 16 Apr 2013 07:36:12 +0000 (16:36 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: If0f06e404697688f7ed7cdf9f7964ec11eb6d703

org.tizen.cli/src/org/tizen/cli/exec/pack/NativeMain.java

index 8c8d0e3..8a3820c 100644 (file)
@@ -28,6 +28,7 @@
 package org.tizen.cli.exec.pack;
 
 import java.io.BufferedReader;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -40,6 +41,7 @@ import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.common.core.command.CommandCancelException;
 import org.tizen.common.core.command.Prompter;
 import org.tizen.common.util.FileUtil;
+import org.tizen.common.util.IOUtil;
 import org.tizen.common.util.OSChecker;
 import org.tizen.common.util.StringUtil;
 
@@ -138,14 +140,24 @@ public class NativeMain extends AbstractLauncher{
         Process cmdP = Runtime.getRuntime().exec(cmdList.toArray(new String[cmdList.size()]));
         
         String line;
-        BufferedReader outReader = new BufferedReader(new InputStreamReader(cmdP.getInputStream()));
-        while((line = outReader.readLine()) != null ) {
-            prompter.notify(line);
-        }
         
-        BufferedReader errReader = new BufferedReader(new InputStreamReader(cmdP.getErrorStream()));
-        while((line = errReader.readLine()) != null) {
-            prompter.error(line);
+        InputStream is = null;
+        InputStream eis = null;
+        try {
+            is = cmdP.getInputStream();
+            BufferedReader outReader = new BufferedReader(new InputStreamReader(is));
+            while((line = outReader.readLine()) != null ) {
+                prompter.notify(line);
+            }
+            
+            eis = cmdP.getErrorStream();
+            BufferedReader errReader = new BufferedReader(new InputStreamReader(eis));
+            while((line = errReader.readLine()) != null) {
+                prompter.error(line);
+            }
+        }
+        finally {
+            IOUtil.tryClose(is, eis);
         }
     
     }