aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-01-13 09:25:34 +0100
committersonartech <sonartech@sonarsource.com>2023-01-13 20:02:46 +0000
commit604e6f12790231546d496e6ad0da53569618078b (patch)
tree134015651c7464953dc1346eff9b165316ff6a5a /server/sonar-ce-task-projectanalysis
parente2d4a8fd280b78c228ed09f023f57b904521b3d1 (diff)
downloadsonarqube-604e6f12790231546d496e6ad0da53569618078b.tar.gz
sonarqube-604e6f12790231546d496e6ad0da53569618078b.zip
SONAR-18195 Missing SCM data might cause a NPE in the Compute Engine
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepository.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepositoryTest.java14
2 files changed, 14 insertions, 2 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepository.java
index f0fc255cd38..3d6418fc752 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepository.java
@@ -81,7 +81,7 @@ public class NewLinesRepository {
// in PRs, we consider changes introduced in this analysis as new, hence subtracting 1.
long referenceDate = useAnalysisDateAsReferenceDate() ? (analysisMetadataHolder.getAnalysisDate() - 1) : periodHolder.getPeriod().getDate();
for (int i = 0; i < allChangesets.length; i++) {
- if (isLineInPeriod(allChangesets[i].getDate(), referenceDate)) {
+ if (allChangesets[i] != null && isLineInPeriod(allChangesets[i].getDate(), referenceDate)) {
lines.add(i + 1);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepositoryTest.java
index a0a33ca30be..9655320f629 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/source/NewLinesRepositoryTest.java
@@ -92,6 +92,18 @@ public class NewLinesRepositoryTest {
}
@Test
+ public void compute_new_lines_using_scm_info_for_period_with_missing_line() {
+ periodHolder.setPeriod(new Period("", null, 1000L));
+ scmInfoRepository.setScmInfo(FILE.getReportAttributes().getRef(), createChangesets(1100L, 900L, null, 800L));
+
+ Optional<Set<Integer>> newLines = repository.getNewLines(FILE);
+
+ assertThat(newLines).isPresent();
+ assertThat(newLines.get()).containsOnly(1);
+ assertThat(repository.newLinesAvailable()).isTrue();
+ }
+
+ @Test
public void compute_new_lines_using_scm_info_for_pullrequest() {
periodHolder.setPeriod(null);
setPullRequest();
@@ -137,7 +149,7 @@ public class NewLinesRepositoryTest {
private Changeset[] createChangesets(Long... dates) {
return Arrays.stream(dates)
- .map(l -> Changeset.newChangesetBuilder().setDate(l).build())
+ .map(l -> l == null ? null : Changeset.newChangesetBuilder().setDate(l).build())
.toArray(Changeset[]::new);
}