]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9199 Fix unclosed inputStream
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 11 May 2017 10:16:36 +0000 (12:16 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Thu, 11 May 2017 10:17:14 +0000 (12:17 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java

index 1e0f5b369bd1ac4140eaae3b38fb88d95c6525c1..ff881a6f75dea7bff8b7707177943aaf3af7a9b5 100644 (file)
@@ -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());
     }