[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] NPE in Repository.resolve

Attached patch fixes a possible NPE in Repository.resolve().

I was trying to submit that through Gerrit, but desperately stopped
after encountering "The contributor must 'sign-off' on the
contribution." ... for a two lines patch ... *LOL*.

-Marc

>From 8da6395cd53d10e99ecae563f0c25a4f71437f30 Mon Sep 17 00:00:00 2001
From: Marc Strapetz <marc.strapetz@xxxxxxxxxxx>
Date: Thu, 16 Jan 2014 16:55:50 +0100
Subject: [PATCH] Fix possible NPE in Repository.resolve

Change-Id: I9b19cd90b338a4c3cae5661c658526b7e98c95d1
---
 org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 77734bf..7e15bec 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -382,7 +382,8 @@ public ObjectId resolve(final String revstr)
 		try {
 			Object resolved = resolve(rw, revstr);
 			if (resolved instanceof String) {
-				return getRef((String) resolved).getLeaf().getObjectId();
+				final Ref ref = getRef((String)resolved);
+				return ref != null ? ref.getLeaf().getObjectId() : null;
 			} else {
 				return (ObjectId) resolved;
 			}
-- 
1.8.3.msysgit.0