Fix possible NPEs in ReplaceRequest.cmd usage in ReceiveCommits

The cmd field is populated by validate(boolean). If this method
fails we may not be able to set results on all ReplaceRequests.
Guard the attempt to access the field with a null check.

Change-Id: Ib0b87f8751f40b25790bd630f9438177b091decc
This commit is contained in:
Shawn O. Pearce
2012-08-06 15:07:29 -07:00
parent 9a147ff332
commit a3a1013678

View File

@@ -1406,7 +1406,7 @@ public class ReceiveCommits {
}
for (ReplaceRequest req : replaceByChange.values()) {
if (req.inputCommand.getResult() == NOT_ATTEMPTED) {
if (req.inputCommand.getResult() == NOT_ATTEMPTED && req.cmd != null) {
batch.addCommand(req.cmd);
}
}
@@ -1414,7 +1414,7 @@ public class ReceiveCommits {
if (newChange != null && newChange.getResult() != NOT_ATTEMPTED) {
// Cancel creations tied to refs/for/ or refs/drafts/ command.
for (ReplaceRequest req : replaceByChange.values()) {
if (req.inputCommand == newChange) {
if (req.inputCommand == newChange && req.cmd != null) {
req.cmd.setResult(Result.REJECTED_OTHER_REASON, "aborted");
}
}