Fix NPE when requesting invalid Change-Id to index

When an invalid Change-Id containing a comma ',' is provided to the
SSH gerrit index changes command, it does not blow up and instead
returns an "Invalid change ID" error and exit code 2.

Change-Id: I97e888e372eb886b9ac9815791a7a725802d736f
Bug: Issue 4911
This commit is contained in:
Luca Milanesio
2016-11-10 17:35:22 +00:00
parent 3b23e70729
commit 650769c46b

View File

@@ -96,9 +96,9 @@ public class ChangeArgumentParser {
}
private List<ChangeControl> changeFromNotesFactory(String id,
final CurrentUser currentUser) throws OrmException {
final CurrentUser currentUser) throws OrmException, UnloggedFailure {
List<ChangeNotes> changes =
changeNotesFactory.create(db, Arrays.asList(Change.Id.parse(id)));
changeNotesFactory.create(db, parseId(id));
return FluentIterable.from(changes)
.transform(new Function<ChangeNotes, ChangeControl>() {
@Override
@@ -108,6 +108,14 @@ public class ChangeArgumentParser {
}).filter(Predicates.notNull()).toList();
}
private List<Change.Id> parseId(String id) throws UnloggedFailure {
try {
return Arrays.asList(new Change.Id(Integer.parseInt(id)));
} catch (NumberFormatException e) {
throw new UnloggedFailure(2, "Invalid change ID " + id, e);
}
}
private ChangeControl controlForChange(ChangeNotes change, CurrentUser user) {
try {
return changeControlFactory.controlFor(change, user);