aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner
diff options
context:
space:
mode:
authorJavier García Orduña <javier.garcia@sonarsource.com>2024-12-06 13:09:31 +0100
committersonartech <sonartech@sonarsource.com>2024-12-06 20:03:27 +0000
commitdd2762c9eabce3ece8aedf71db4d78b4153bb8bd (patch)
treeee2da45cd207c0306037b413772b979ad79dfd2c /sonar-scanner-engine/src/main/java/org/sonar/scanner
parent00268b5200a6f329e14e3e6b910768cf454cd64c (diff)
downloadsonarqube-dd2762c9eabce3ece8aedf71db4d78b4153bb8bd.tar.gz
sonarqube-dd2762c9eabce3ece8aedf71db4d78b4153bb8bd.zip
SONAR-22185 SARIF issues are not imported for some location URI format
Co-authored-by: antoine.vinot <antoine.vinot@sonarsource.com>
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/LocationMapper.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/LocationMapper.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/LocationMapper.java
index 4b668c90d56..97093c2e0a9 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/LocationMapper.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/sarif/LocationMapper.java
@@ -31,6 +31,7 @@ import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
+import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.predicates.AbstractFilePredicate;
@@ -113,12 +114,22 @@ public class LocationMapper {
private static File getFileFromAbsoluteUriOrPath(String filePath) {
URI uri = URI.create(filePath);
if (uri.isAbsolute()) {
- return new File(uri);
+ return getFileFromAbsoluteUri(filePath, uri);
} else {
return new File(filePath);
}
}
+ @NotNull
+ private static File getFileFromAbsoluteUri(String filePath, URI uri) {
+ String path = uri.getPath();
+ if (StringUtils.isNotBlank(path)) {
+ return new File(path);
+ } else {
+ throw new IllegalArgumentException("Invalid file scheme URI: " + filePath);
+ }
+ }
+
@VisibleForTesting
static class IsPredicate extends AbstractFilePredicate {
private final Path path;