Fix comments without approvals
CommentAddedEvent's approvals field is null (see gerrit's
ChangeHookRunner), if there are no approvals, so checking only for
approvals.length or iterating over approvals raised a
NullPointerException if the comment did not provide approvals.
Change-Id: I99153554ced10368556bc9354ab2de3188df764d
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
index 0c8be83..36fffd0 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterAddComment.java
@@ -85,7 +85,7 @@
private String getComment(CommentAddedEvent commentAdded) {
StringBuilder comment = new StringBuilder(getCommentPrefix(commentAdded.change));
- if (commentAdded.approvals.length > 0) {
+ if (commentAdded.approvals != null && commentAdded.approvals.length > 0) {
comment.append("Code-Review: ");
for (ApprovalAttribute approval : commentAdded.approvals) {
String value = getApprovalValue(approval);
diff --git a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java
index 8fc99ef..7b2e7bd 100644
--- a/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java
+++ b/hooks-its/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java
@@ -62,9 +62,11 @@
List<Condition> conditions = new ArrayList<Condition>();
conditions.add(new Condition("change", "commented"));
- for (ApprovalAttribute approval : hook.approvals) {
- addApprovalCategoryCondition(conditions, approval.type, approval.value);
- };
+ if (hook.approvals != null) {
+ for (ApprovalAttribute approval : hook.approvals) {
+ addApprovalCategoryCondition(conditions, approval.type, approval.value);
+ }
+ }
performAction(hook.change,
conditions.toArray(new Condition[conditions.size()]));