Fix NPE upon commit that is not a patch set thus no change note involved
Before this fix, NullPointerException-s showed in error_log when 'ps'
was null. Creating a project with an empty commit led to that NPE, among
other likely cases.
Fix this so no attempt at creating a change note is made for a commit
that does not involve a patch set.
Log an info when such direct-push cases happen.
Change-Id: I455e0a4d58e78168ba4f5c55cd272232d4120ab3
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
index 3ca3d40..249700a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -157,13 +157,18 @@
for (RevCommit c : rw) {
PatchSet ps = loadPatchSet(c, branch);
- ChangeNotes notes =
- notesFactory.create(reviewDb, project, ps.getId().getParentKey());
- ObjectId content = createNoteContent(notes, ps);
- if (content != null) {
- monitor.update(1);
- getNotes().set(c, content);
- getMessage().append("* ").append(c.getShortMessage()).append("\n");
+ if (ps != null) {
+ ChangeNotes notes = notesFactory.create(reviewDb, project,
+ ps.getId().getParentKey());
+ ObjectId content = createNoteContent(notes, ps);
+ if (content != null) {
+ monitor.update(1);
+ getNotes().set(c, content);
+ getMessage().append("* ").append(c.getShortMessage()).append("\n");
+ }
+ } else {
+ log.debug("no note for this commit since it is a direct push: "
+ + c.getName().substring(0, 7));
}
}
}