aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>2023-06-07 17:18:52 +0200
committersonartech <sonartech@sonarsource.com>2023-06-07 20:02:43 +0000
commit2bb7acebc75ff7ae6cb0a413ac298f048a43d534 (patch)
treeba395f4cab6fb308bdbc983c46898c02892bdddc /sonar-scanner-engine
parent1a607ea5d761c72dc2fc1ebea8d2c92c72af3ced (diff)
downloadsonarqube-2bb7acebc75ff7ae6cb0a413ac298f048a43d534.tar.gz
sonarqube-2bb7acebc75ff7ae6cb0a413ac298f048a43d534.zip
SONAR-19160 handle missing locations in SARIF import. (#8476)
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/ResultMapper.java6
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/sarif/ResultMapperTest.java14
2 files changed, 17 insertions, 3 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/ResultMapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/ResultMapper.java
index 213b03c3634..7668c477b57 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/ResultMapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/ResultMapper.java
@@ -22,6 +22,7 @@ package org.sonar.scanner.externalissue.sarif;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.SensorContext;
@@ -72,10 +73,11 @@ public class ResultMapper {
private void mapLocations(Result result, NewExternalIssue newExternalIssue) {
NewIssueLocation newIssueLocation = newExternalIssue.newLocation();
- if (result.getLocations().isEmpty()) {
+ Set<Location> locations = result.getLocations();
+ if (locations == null || locations.isEmpty()) {
newExternalIssue.at(locationMapper.fillIssueInProjectLocation(result, newIssueLocation));
} else {
- Location firstLocation = result.getLocations().iterator().next();
+ Location firstLocation = locations.iterator().next();
NewIssueLocation primaryLocation = fillFileOrProjectLocation(result, newIssueLocation, firstLocation);
newExternalIssue.at(primaryLocation);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/sarif/ResultMapperTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/sarif/ResultMapperTest.java
index c6eaed7f556..309a8ed9503 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/sarif/ResultMapperTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/sarif/ResultMapperTest.java
@@ -129,7 +129,19 @@ public class ResultMapperTest {
}
@Test
- public void mapResult_whenLocationNotFound_createsProjectLocation() {
+ public void mapResult_whenLocationsIsEmpty_createsProjectLocation() {
+ NewExternalIssue newExternalIssue = resultMapper.mapResult(DRIVER_NAME, WARNING, result);
+
+ verify(locationMapper).fillIssueInProjectLocation(result, newExternalIssueLocation);
+ verifyNoMoreInteractions(locationMapper);
+ verify(newExternalIssue).at(newExternalIssueLocation);
+ verify(newExternalIssue, never()).addLocation(any());
+ verify(newExternalIssue, never()).addFlow(any());
+ }
+
+ @Test
+ public void mapResult_whenLocationsIsNull_createsProjectLocation() {
+ when(result.getLocations()).thenReturn(null);
NewExternalIssue newExternalIssue = resultMapper.mapResult(DRIVER_NAME, WARNING, result);
verify(locationMapper).fillIssueInProjectLocation(result, newExternalIssueLocation);