]> source.dussan.org Git - sonarqube.git/commitdiff
fix resource leak
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 8 Jan 2015 09:01:17 +0000 (10:01 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 8 Jan 2015 09:01:50 +0000 (10:01 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportService.java

index ab4f4a874151d501edfc6c3c9d9b422bf6b5dc87..14e6a66458bada2e2f7494e125481176e5b5d245 100644 (file)
@@ -72,14 +72,14 @@ public class AnalysisReportService implements ServerComponent {
   void loadResources(ComputeEngineContext context) {
     File file = new File(context.getReportDirectory(), "components.json");
 
-    try {
-      InputStream resourcesStream = new FileInputStream(file);
+    try (InputStream resourcesStream = new FileInputStream(file)) {
       String json = IOUtils.toString(resourcesStream);
       ReportComponents reportComponents = ReportComponents.fromJson(json);
       context.addResources(reportComponents);
     } catch (IOException e) {
       throw new IllegalStateException("Failed to read issues", e);
     }
+
   }
 
   @VisibleForTesting
@@ -97,9 +97,8 @@ public class AnalysisReportService implements ServerComponent {
     File issuesFile = new File(context.getReportDirectory(), "issues.json");
     List<DefaultIssue> issues = new ArrayList<>(MAX_ISSUES_SIZE);
 
-    try {
-      InputStream issuesStream = new FileInputStream(issuesFile);
-      JsonReader reader = new JsonReader(new InputStreamReader(issuesStream));
+    try (InputStream issuesStream = new FileInputStream(issuesFile);
+      JsonReader reader = new JsonReader(new InputStreamReader(issuesStream))) {
       reader.beginArray();
       while (reader.hasNext()) {
         ReportIssue reportIssue = gson.fromJson(reader, ReportIssue.class);