From 4e8578dce0063186c6ea63e30a687f2fbfdf7db9 Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Tue, 23 Mar 2010 13:27:02 +0300 Subject: [PATCH] git4idea: Ensuring that either exception is thrown or non-null stdout is returned from GitSimpleHandler.run() --- .../git4idea/commands/GitSimpleHandler.java | 27 +++++++++++-------- .../src/git4idea/commands/StringScanner.java | 4 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java b/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java index 3cbf8b19cd49..98498c575173 100644 --- a/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitSimpleHandler.java @@ -192,18 +192,23 @@ public class GitSimpleHandler extends GitHandler { final String[] result = new String[1]; addListener(new GitHandlerListener() { public void processTerminated(final int exitCode) { - if (exitCode == 0 || isIgnoredErrorCode(exitCode)) { - result[0] = getStdout(); + try { + if (exitCode == 0 || isIgnoredErrorCode(exitCode)) { + result[0] = getStdout(); + } + else { + String msg = getStderr(); + if (msg.length() == 0) { + msg = getStdout(); + } + if (msg.length() == 0) { + msg = GitBundle.message("git.error.exit", exitCode); + } + ex[0] = new VcsException(msg); + } } - else { - String msg = getStderr(); - if (msg.length() == 0) { - msg = getStdout(); - } - if (msg.length() == 0) { - msg = GitBundle.message("git.error.exit", exitCode); - } - ex[0] = new VcsException(msg); + catch (Exception t) { + ex[0] = new VcsException(t.toString(), t); } } diff --git a/plugins/git4idea/src/git4idea/commands/StringScanner.java b/plugins/git4idea/src/git4idea/commands/StringScanner.java index 47e3d485101e..86d6440f83a3 100644 --- a/plugins/git4idea/src/git4idea/commands/StringScanner.java +++ b/plugins/git4idea/src/git4idea/commands/StringScanner.java @@ -15,6 +15,8 @@ */ package git4idea.commands; +import org.jetbrains.annotations.NotNull; + /** * A parser of strings that is oriented to scanning typical git outputs */ @@ -33,7 +35,7 @@ public class StringScanner { * * @param text the text to scan */ - public StringScanner(final String text) { + public StringScanner(@NotNull final String text) { myText = text; myPosition = 0; }