[Fix] NPE exception if label value is null
Change-Id: If3db94d2d06698cbd96f73d5637df1aeb9543f61
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
index 55f0300..e703b60 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/AddApprovalsStep.java
@@ -109,13 +109,13 @@
, pluginName, labelName, a.username, changeInfo.id));
continue;
}
- approvals.add(new PatchSetApproval(
- new PatchSetApproval.Key(change.currentPatchSetId(), user,
- labelType.getLabelId()), a.value.shortValue(),
- MoreObjects.firstNonNull(a.date, TimeUtil.nowTs())));
+ short shortValue = a.value != null ? a.value.shortValue() : 0;
+ approvals.add(new PatchSetApproval(new PatchSetApproval.Key(change
+ .currentPatchSetId(), user, labelType.getLabelId()), shortValue,
+ MoreObjects.firstNonNull(a.date, TimeUtil.nowTs())));
ChangeUpdate update = updateFactory.create(ctrl);
- if (a.value != 0) {
- update.putApproval(labelName, a.value.shortValue());
+ if (shortValue != 0) {
+ update.putApproval(labelName, shortValue);
} else {
update.removeApproval(labelName);
}