MISC: Code Refactorings. Prevented null pointer dereferences. 00/13500/1
authorkh5325.kim <kh5325.kim@samsung.com>
Mon, 9 Dec 2013 03:47:35 +0000 (12:47 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Mon, 9 Dec 2013 03:47:35 +0000 (12:47 +0900)
Code Refactorings. Prevented null pointer dereferences.

Change-Id: I6dbf92acf1e0821b8d643e4590a428edc4487719
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/command/GitCommand.java
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/command/git/JGitCLI.java
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/command/git/StatusCommand.java
org.tizen.common.ui/src/org/tizen/common/ui/commandbar/command/launcher/TizenHandler.java

index 5abae6d..b4f8e00 100644 (file)
@@ -46,10 +46,14 @@ import org.tizen.common.ui.commandbar.command.launcher.CommandLauncher;
 import org.tizen.common.ui.view.console.ConsoleManager;
 import org.tizen.common.util.ArrayUtil;
 import org.tizen.common.util.CollectionUtil;
+import org.tizen.common.util.IOUtil;
 import org.tizen.common.util.ViewUtil;
 
 public class GitCommand extends ConsoleCommand {
     public void run(final Executor executor, final ExecutionContext context) throws Exception {
+        if (ViewUtil.getWorkbenchWindow() == null)
+            return;
+
         ConsoleManager console = new ConsoleManager(CONSOLE_NAME, true);
         context.setValue(CONTEXT_CONSOLE, console);
         IStructuredSelection selection = (IStructuredSelection) ViewUtil.getWorkbenchWindow().getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
@@ -75,8 +79,9 @@ public class GitCommand extends ConsoleCommand {
 
         //final PrintStream oldOut = System.out;
         //final PrintStream oldErr = System.err;
+        PrintStream out = null;
         try {
-            PrintStream out = new PrintStream(console.getMessageConsoleStream());
+            out = new PrintStream(console.getMessageConsoleStream());
             //System.setErr(out);
             //System.setOut(out);
 
@@ -88,6 +93,7 @@ public class GitCommand extends ConsoleCommand {
         } finally {
             //System.setErr(oldErr);
             //System.setOut(oldOut);
+            IOUtil.tryClose(out);
         }
     }
 
index e099919..dfa0749 100644 (file)
@@ -75,6 +75,8 @@ public class JGitCLI extends Main {
             //  - To prevent System.exit() codes in org.eclipse.jgit.pgm.Main\r
             //run(args.toArray(new String[0]));\r
             URL fileURL = PluginUtil.getFileURLinBundle(Activator.PLUGIN_ID, "lib/jgit-cli.jar");\r
+            if (fileURL == null)\r
+                throw new Exception("Failed to find lib/jgit-cli.jar");\r
             String jarPath = fileURL.getPath();\r
             if (OSChecker.isWindows() && jarPath.startsWith("/")) {\r
                 // /D:/common-eplugin/org.tizen.common.ui/lib/jgit-cli.jar\r
index 96f9260..05bd1d4 100644 (file)
@@ -135,7 +135,8 @@ public class StatusCommand extends Command {
         if (revision.length() == 0)\r
             throw new IllegalArgumentException("Revision can not be empty");\r
 \r
-        return parse(repository, resolve(repository, revision));\r
+        ObjectId resolvedId = resolve(repository, revision);\r
+        return (resolvedId != null) ? parse(repository, resolvedId) : null;\r
     }\r
 \r
     private static ObjectId resolve(final Repository repository, final String revision) {\r
@@ -277,7 +278,7 @@ public class StatusCommand extends Command {
             // TODO: Not supported\r
             // If we call createRenameDetector(), rename can be detected. But compute can be very long running.\r
             //  cf.)) http://stackoverflow.com/questions/17296278/jgit-detect-rename-in-working-copy/17302068\r
-            printStatusMore(String.format("renamed:   %s -> %s", one));\r
+            printStatusMore(String.format("renamed:   %s -> %s", one, one));\r
             break;\r
         }\r
         printStatusMore("\n");\r
index 6f364a1..73f6089 100644 (file)
@@ -99,6 +99,6 @@ public class TizenHandler implements Handler {
     }\r
 \r
     public String formatVisiting(int answerNumber, String link) {\r
-        return String.format(" Visiting... [%d]%n", answerNumber + 1, link);\r
+        return String.format(" Visiting... [%d]%n", answerNumber + 1);\r
     }\r
 }\r