Browse Source

Fix NPE when previous technical debt was null

tags/4.1-RC1
Julien Lancelot 10 years ago
parent
commit
d2b96c467a

+ 1
- 1
sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java View File

@@ -204,7 +204,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
TechnicalDebt oldValue = issue.technicalDebt();
if (!Objects.equal(value, oldValue)) {
issue.setTechnicalDebt(value);
issue.setFieldChange(context, TECHNICAL_DEBT, oldValue.toLong(), value.toLong());
issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toLong() : oldValue, value != null ? value.toLong() : null);
issue.setUpdateDate(context.date());
issue.setChanged(true);
return true;

+ 27
- 0
sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java View File

@@ -378,6 +378,33 @@ public class IssueUpdaterTest {
assertThat(diff.newValue()).isEqualTo(TechnicalDebt.of(15, 0, 0).toLong());
}

@Test
public void set_past_technical_debt_without_previous_value() throws Exception {
issue.setTechnicalDebt(TechnicalDebt.of(15, 0, 0));
boolean updated = updater.setPastTechnicalDebt(issue, null, context);
assertThat(updated).isTrue();
assertThat(issue.technicalDebt()).isEqualTo(TechnicalDebt.of(15, 0, 0));
assertThat(issue.mustSendNotifications()).isFalse();

FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT);
assertThat(diff.oldValue()).isNull();
assertThat(diff.newValue()).isEqualTo(TechnicalDebt.of(15, 0, 0).toLong());
}

@Test
public void set_past_technical_debt_with_null_new_value() throws Exception {
issue.setTechnicalDebt(null);
TechnicalDebt previousDebt = TechnicalDebt.of(10, 0, 0);
boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context);
assertThat(updated).isTrue();
assertThat(issue.technicalDebt()).isNull();
assertThat(issue.mustSendNotifications()).isFalse();

FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT);
assertThat(diff.oldValue()).isEqualTo(TechnicalDebt.of(10, 0, 0).toLong());
assertThat(diff.newValue()).isNull();
}

@Test
public void set_message() throws Exception {
boolean updated = updater.setMessage(issue, "the message", context);

Loading…
Cancel
Save