diff options
author | Klaudio Sinani <klaudio.sinani@sonarsource.com> | 2022-11-08 14:48:31 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-11-08 20:02:59 +0000 |
commit | b2904b7b5133f62d75b96d43c36fe1464c05d8b0 (patch) | |
tree | a87a895869928d6ba329e5c07f8628f0e1249c3d /sonar-scanner-engine/src/main/java | |
parent | d488345162101994b8e6f9fbe51dd4ed34ff679d (diff) | |
download | sonarqube-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.java | 9 |
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; + } } |