aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-05-11 12:16:36 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-05-11 12:17:14 +0200
commitad9aff18613d47ea6516756815102295cb13c9a2 (patch)
treee48f93f940959452abcd62dbc165e7d36bfe2f83 /sonar-plugin-api
parent84c3c4c71a7fadb52b7214b9514f5227835c2cac (diff)
downloadsonarqube-ad9aff18613d47ea6516756815102295cb13c9a2.tar.gz
sonarqube-ad9aff18613d47ea6516756815102295cb13c9a2.zip
SONAR-9199 Fix unclosed inputStream
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 1e0f5b369bd..ff881a6f75d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -86,11 +86,12 @@ public class DefaultInputFile extends DefaultInputComponent implements InputFile
return contents;
} else {
ByteArrayOutputStream result = new ByteArrayOutputStream();
- byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- int length;
- InputStream inputStream = inputStream();
- while ((length = inputStream.read(buffer)) != -1) {
- result.write(buffer, 0, length);
+ try (InputStream inputStream = inputStream()) {
+ byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+ int length;
+ while ((length = inputStream.read(buffer)) != -1) {
+ result.write(buffer, 0, length);
+ }
}
return result.toString(charset().name());
}