From 98684818a838815fe526ac3653f849c4f62559f5 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 26 Aug 2014 15:06:46 +0900 Subject: [PATCH 1/3] Fix NPE when submitting review with inline comments via REST NPE occurs when submitting a review with inline comments in the format: { "comments": { "test.txt": [ { "line": 1, "message": "comment" }, ] } } The comma following the closing brace after the `"message": "comment"` line seems to be causing an iterator with a null element to be generated. NPE does not occur when the comma is omitted. To prevent the NPE remove the null element from the iterator. Change-Id: I248739fce955522f7ee4a93441e48914342d3d7d --- .../main/java/com/google/gerrit/server/change/PostReview.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java index 022538796c..6c28158668 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java @@ -282,6 +282,10 @@ public class PostReview implements RestModifyView Iterator listItr = list.iterator(); while (listItr.hasNext()) { Comment c = listItr.next(); + if (c == null) { + listItr.remove(); + continue; + } if (c.line < 0) { throw new BadRequestException(String.format( "negative line number %d not allowed on %s", From ccfc8eb70be2cc8cd67170b5966e6152260d60bb Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 27 Aug 2014 15:06:42 -0700 Subject: [PATCH 2/3] Fix NPE in /projects/{name}/children?recursive when a parent is missing If there is a broken edge in the parent graph treat it as having no children instead of throwing NPE and failing the REST API call. Change-Id: Ib72f76f04f5804d2b953f0951d3304fc1d6329a2 --- .../google/gerrit/server/project/ListChildProjects.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/ListChildProjects.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/ListChildProjects.java index 58abe40082..5f21e7054e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/ListChildProjects.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/ListChildProjects.java @@ -25,6 +25,7 @@ import com.google.inject.Inject; import org.kohsuke.args4j.Option; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -94,7 +95,13 @@ public class ListChildProjects implements RestReadView { node.addChild(key); } } - return getChildProjectsRecursively(projects.get(parent)); + + ProjectNode n = projects.get(parent); + if (n != null) { + return getChildProjectsRecursively(n); + } else { + return Collections.emptyList(); + } } private List getChildProjectsRecursively(ProjectNode p) { From a14b38b3b0b2e1e001e382e3897571df4acd4449 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 1 Sep 2014 14:50:42 +0900 Subject: [PATCH 3/3] Fix NPE when ReviewInput's message is empty Bug: Issue 2877 Change-Id: I3d31af8cdcc26c2dc48c316542f55c402fd63832 --- .../main/java/com/google/gerrit/server/change/PostReview.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java index 022538796c..43668e63e4 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java @@ -287,7 +287,7 @@ public class PostReview implements RestModifyView "negative line number %d not allowed on %s", c.line, path)); } - c.message = Strings.emptyToNull(c.message).trim(); + c.message = Strings.nullToEmpty(c.message).trim(); if (c.message.isEmpty()) { listItr.remove(); }