Skip to content

Commit 796dcf4

Browse files
#152 Handling generated classes
Generated classes aren't in Git and don't have a Git history, causing an NPE when a Git lookup is attempted
1 parent 9ddd7f2 commit 796dcf4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

change-proneness-ranker/src/main/java/org/hjug/git/GitLogReader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ public ScmLogInfo fileLog(String path) throws GitAPIException, IOException {
7878
}
7979

8080
// based on https://stackoverflow.com/a/59274329/346247
81-
int mostRecentCommit = git.log()
82-
.add(branchId)
83-
.addPath(path)
84-
.setMaxCount(1)
85-
.call()
86-
.iterator()
87-
.next()
88-
.getCommitTime();
81+
Iterator<RevCommit> iterator =
82+
git.log().add(branchId).addPath(path).setMaxCount(1).call().iterator();
83+
84+
if (!iterator.hasNext()) {
85+
return new ScmLogInfo(path, null, earliestCommit, earliestCommit, commitCount);
86+
}
87+
88+
int mostRecentCommit = iterator.next().getCommitTime();
8989

9090
return new ScmLogInfo(path, null, earliestCommit, mostRecentCommit, commitCount);
9191
}

0 commit comments

Comments
 (0)