Skip to content

Commit afd89c8

Browse files
Vladimir Kotalahornace
authored andcommitted
deal with null Repository in getLastHistoryEntry()
fixes #3630
1 parent 34c930b commit afd89c8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/HistoryGuru.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ public History getHistoryUI(File file) throws HistoryException {
237237

238238
public HistoryEntry getLastHistoryEntry(File file, boolean ui) throws HistoryException {
239239
final Repository repo = getRepository(file);
240-
return repo.getLastHistoryEntry(file, ui);
240+
if (repo != null) {
241+
return repo.getLastHistoryEntry(file, ui);
242+
}
243+
return null;
241244
}
242245

243246
/**

opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.junit.jupiter.api.Assertions.assertEquals;
2727
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2828
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNull;
2930
import static org.junit.jupiter.api.Assertions.assertTrue;
3031
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.CVS;
3132
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
@@ -279,4 +280,11 @@ public void testScanningDepth() throws IOException {
279280

280281
env.setScanningDepth(originalScanDepth);
281282
}
283+
284+
@Test
285+
void testGetLastHistoryEntry() throws HistoryException {
286+
HistoryGuru instance = HistoryGuru.getInstance();
287+
File file = new File("/nonexistent");
288+
assertNull(instance.getLastHistoryEntry(file, true));
289+
}
282290
}

0 commit comments

Comments
 (0)