From 7b01a5369210ef68dd2934db72861b3145495d3f Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 28 Feb 2014 07:15:08 +0100 Subject: [PATCH] Fix NPE when WorkingTreeIterator does not have a repository set It's strange that we have that member since it is not so clear when it it set or not. Change-Id: I53903a264f46866d249901a3cd9f9295028aa6bd Signed-off-by: Matthias Sohn --- .../eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java | 6 ++++-- .../org/eclipse/jgit/treewalk/WorkingTreeIterator.java | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java index 484467b24..2b2d65e9b 100644 --- a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java +++ b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java @@ -114,7 +114,8 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase { assertEquals("link", dci.getEntryPathString()); // test - assertFalse(fti.isModified(dci.getDirCacheEntry(), true)); + assertFalse(fti.isModified(dci.getDirCacheEntry(), true, + db.newObjectReader())); } /** @@ -195,6 +196,7 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase { assertEquals("link", dci.getEntryPathString()); // test - assertTrue(fti.isModified(dci.getDirCacheEntry(), true)); + assertTrue(fti.isModified(dci.getDirCacheEntry(), true, + db.newObjectReader())); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 633865ed4..dd59afc38 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -922,7 +922,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { } else { if (mode == FileMode.SYMLINK.getBits()) return !new File(readContentAsNormalizedString(current())) - .equals(new File((readContentAsNormalizedString(entry)))); + .equals(new File((readContentAsNormalizedString(entry, + reader)))); // Content differs: that's a real change, perhaps if (reader == null) // deprecated use, do no further checks return true; @@ -971,9 +972,9 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { } } - private String readContentAsNormalizedString(DirCacheEntry entry) - throws MissingObjectException, IOException { - ObjectLoader open = repository.open(entry.getObjectId()); + private static String readContentAsNormalizedString(DirCacheEntry entry, + ObjectReader reader) throws MissingObjectException, IOException { + ObjectLoader open = reader.open(entry.getObjectId()); byte[] cachedBytes = open.getCachedBytes(); return FS.detect().normalize(RawParseUtils.decode(cachedBytes)); }