aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2022-11-08 14:48:31 +0100
committersonartech <sonartech@sonarsource.com>2022-11-08 20:02:59 +0000
commitb2904b7b5133f62d75b96d43c36fe1464c05d8b0 (patch)
treea87a895869928d6ba329e5c07f8628f0e1249c3d /sonar-scanner-engine/src/main/java
parentd488345162101994b8e6f9fbe51dd4ed34ff679d (diff)
downloadsonarqube-b2904b7b5133f62d75b96d43c36fe1464c05d8b0.tar.gz
sonarqube-b2904b7b5133f62d75b96d43c36fe1464c05d8b0.zip
SONAR-17571 Ensure file existence prior to file size assessment
Diffstat (limited to 'sonar-scanner-engine/src/main/java')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
index caf0ad0d76f..3a6fee428d5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java
@@ -120,9 +120,8 @@ public class FileIndexer {
return;
}
- long maxFileSize = properties.fileSizeLimit();
- if (Files.size(realAbsoluteFile) > maxFileSize * 1024L * 1024L) {
- LOG.warn("File '{}' is bigger than {}MB and as consequence is removed from the analysis scope.", realAbsoluteFile.toAbsolutePath(), maxFileSize);
+ if (Files.exists(realAbsoluteFile) && isFileSizeBiggerThanLimit(realAbsoluteFile)) {
+ LOG.warn("File '{}' is bigger than {}MB and as consequence is removed from the analysis scope.", realAbsoluteFile.toAbsolutePath(), properties.fileSizeLimit());
return;
}
@@ -282,4 +281,8 @@ public class FileIndexer {
private static String pluralizeFiles(int count) {
return count == 1 ? "file" : "files";
}
+
+ private boolean isFileSizeBiggerThanLimit(Path filePath) throws IOException {
+ return Files.size(filePath) > properties.fileSizeLimit() * 1024L * 1024L;
+ }
}