aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-07-12 12:31:13 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-07-12 12:31:13 +0200
commitf8719e3723661704e60c8902ab60d0a3b8b931cd (patch)
treea7437622660ce2184593fb0b87026e2b0ab7eafb /plugins/sonar-xoo-plugin/src
parent0acf0fe5f8bd8cf7c188dca14ed3c379b8fe93fb (diff)
downloadsonarqube-f8719e3723661704e60c8902ab60d0a3b8b931cd.tar.gz
sonarqube-f8719e3723661704e60c8902ab60d0a3b8b931cd.zip
Fix unclosed resource
Diffstat (limited to 'plugins/sonar-xoo-plugin/src')
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/NoSonarSensor.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/NoSonarSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/NoSonarSensor.java
index 45d6b9dcb75..d57e2f1eb93 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/NoSonarSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/NoSonarSensor.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;
+import java.util.stream.Stream;
import org.sonar.api.batch.Phase;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.Sensor;
@@ -57,12 +58,14 @@ public class NoSonarSensor implements Sensor {
try {
Set<Integer> noSonarLines = new HashSet<>();
int[] lineCounter = {1};
- Files.lines(inputFile.path(), context.fileSystem().encoding()).forEachOrdered(lineStr -> {
- if (lineStr.contains("//NOSONAR")) {
- noSonarLines.add(lineCounter[0]);
- }
- lineCounter[0]++;
- });
+ try (Stream<String> stream = Files.lines(inputFile.path(), context.fileSystem().encoding())) {
+ stream.forEachOrdered(lineStr -> {
+ if (lineStr.contains("//NOSONAR")) {
+ noSonarLines.add(lineCounter[0]);
+ }
+ lineCounter[0]++;
+ });
+ }
noSonarFilter.noSonarInFile(inputFile, noSonarLines);
} catch (IOException e) {
throw new IllegalStateException("Fail to process " + inputFile, e);