]> source.dussan.org Git - jgit.git/commitdiff
Guard agains null ReflogReader if named ref does not exist 21/48521/3
authorAndrey Loskutov <loskutov@gmx.de>
Sun, 24 May 2015 07:15:15 +0000 (09:15 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 25 May 2015 20:58:14 +0000 (22:58 +0200)
Follow up on egit bug 466973.

Change-Id: Idd83d87803e86b25f106dfd725214b5a3ec5171c
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

index 6cbcd0673593a5d686b0581ff1072ef1fbe368b5..7923fd49bef48bf7a462d9a10d75c9c5482f642b 100644 (file)
@@ -52,6 +52,7 @@ import java.util.List;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.InvalidRefNameException;
 import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.api.errors.RefNotFoundException;
 import org.eclipse.jgit.errors.LockFailedException;
 import org.eclipse.jgit.internal.JGitText;
 import org.eclipse.jgit.internal.storage.file.ReflogWriter;
@@ -184,6 +185,10 @@ public class StashDropCommand extends GitCommand<ObjectId> {
                List<ReflogEntry> entries;
                try {
                        ReflogReader reader = repo.getReflogReader(R_STASH);
+                       if (reader == null) {
+                               throw new RefNotFoundException(MessageFormat
+                                               .format(JGitText.get().refNotResolved, stashRef));
+                       }
                        entries = reader.getReverseEntries();
                } catch (IOException e) {
                        throw new JGitInternalException(JGitText.get().stashDropFailed, e);
index fa28763f0dffaeb8d00ce8bf71325355762f524a..fc7dca2d434bbcdf8473ead6d2469eee75d5d834 100644 (file)
@@ -751,8 +751,11 @@ public abstract class Repository implements AutoCloseable {
 
        private String resolveReflogCheckout(int checkoutNo)
                        throws IOException {
-               List<ReflogEntry> reflogEntries = getReflogReader(Constants.HEAD)
-                               .getReverseEntries();
+               ReflogReader reader = getReflogReader(Constants.HEAD);
+               if (reader == null) {
+                       return null;
+               }
+               List<ReflogEntry> reflogEntries = reader.getReverseEntries();
                for (ReflogEntry entry : reflogEntries) {
                        CheckoutEntry checkout = entry.parseCheckout();
                        if (checkout != null)
@@ -773,6 +776,11 @@ public abstract class Repository implements AutoCloseable {
                }
                assert number >= 0;
                ReflogReader reader = getReflogReader(ref.getName());
+               if (reader == null) {
+                       throw new RevisionSyntaxException(
+                                       MessageFormat.format(JGitText.get().reflogEntryNotFound,
+                                                       Integer.valueOf(number), ref.getName()));
+               }
                ReflogEntry entry = reader.getReverseEntry(number);
                if (entry == null)
                        throw new RevisionSyntaxException(MessageFormat.format(