Handle null reviewer input in PostReviewers

Some malformed or mistyped input may get through GSON's lenient parser
and populate PostReviewers.Input.reviewer as null. Return 400 in this
case instead of causing an NPE.

Change-Id: I1cea274796ab5f31a423329a35c34bbb9809de92
This commit is contained in:
Dave Borowitz
2013-03-04 14:23:30 -08:00
parent f9d5de9248
commit 73cb38bac5

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.common.data.LabelTypes;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestModifyView;
@@ -123,8 +124,11 @@ public class PostReviewers implements RestModifyView<ChangeResource, Input> {
@Override
public PostResult apply(ChangeResource rsrc, Input input)
throws ResourceNotFoundException, AuthException, OrmException,
EmailException {
throws BadRequestException, ResourceNotFoundException, AuthException,
OrmException, EmailException {
if (input.reviewer == null) {
throw new BadRequestException("missing reviewer field");
}
Account.Id accountId = parser.parse(rsrc, input.reviewer);
try {
if (accountId != null) {