Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2015-09-27 09:01:01 -0400
committerMatthias Sohn2015-09-27 16:58:25 -0400
commitfcb1b730f76867864c420beabe7dbbd57e9b33f7 (patch)
tree4d95fac34ada07807b704e8f74e7b88b63045d2e
parente4993d97de3f2f7a36f0c075227f809c69de8ae7 (diff)
downloadegit-fcb1b730f76867864c420beabe7dbbd57e9b33f7.tar.gz
egit-fcb1b730f76867864c420beabe7dbbd57e9b33f7.tar.xz
egit-fcb1b730f76867864c420beabe7dbbd57e9b33f7.zip
Fixed potential NPE in GitFlowRepository::findHead
- RevWalk::parseCommit cannot take null-argument - added nullable annotation and doc Change-Id: I92656928211c868d22291e1ade9fa21792101df6 Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu>
-rw-r--r--org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
index bd8b66901..eaf6ada3e 100644
--- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
+++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/GitFlowRepository.java
@@ -18,6 +18,7 @@ import java.util.List;
import org.eclipse.egit.gitflow.internal.CoreText;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@@ -158,12 +159,17 @@ public class GitFlowRepository {
/**
* @param branchName
- * @return HEAD commit on branch branchName
+ * @return HEAD commit on branch branchName or {@literal null} if
+ * {@code branchName} could not be resolved.
*/
- public RevCommit findHead(String branchName) {
+ public @Nullable RevCommit findHead(String branchName) {
try (RevWalk walk = new RevWalk(repository)) {
try {
- ObjectId head = repository.resolve(R_HEADS + branchName);
+ String revstr = R_HEADS + branchName;
+ ObjectId head = repository.resolve(revstr);
+ if (head == null) {
+ return null;
+ }
return walk.parseCommit(head);
} catch (RevisionSyntaxException | IOException e) {
throw new RuntimeException(e);

Back to the top