Browse Source

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 <matthias.sohn@sap.com>
stable-3.3
Robin Rosenberg 11 years ago committed by Matthias Sohn
parent
commit
7b01a53692
  1. 6
      org.eclipse.jgit.java7.test/src/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java
  2. 9
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

6
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()));
}
}

9
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));
}

Loading…
Cancel
Save