]> source.dussan.org Git - sonarqube.git/commitdiff
Fix Quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 29 Jul 2016 14:34:35 +0000 (16:34 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 29 Jul 2016 14:38:45 +0000 (16:38 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityIndexer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java

index a1db8436737ecff61e0a41c409d0c21099ea716f..2051957bf42e8c57b66fed817798eb5904863374 100644 (file)
@@ -122,9 +122,9 @@ class JavaProcessLauncher {
       props.setProperty(PROPERTY_PROCESS_INDEX, Integer.toString(javaCommand.getProcessId().getIpcIndex()));
       props.setProperty(PROPERTY_TERMINATION_TIMEOUT, String.valueOf(timeouts.getTerminationTimeout()));
       props.setProperty(PROPERTY_SHARED_PATH, tempDir.getAbsolutePath());
-      OutputStream out = new FileOutputStream(propertiesFile);
-      props.store(out, String.format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey()));
-      out.close();
+      try (OutputStream out = new FileOutputStream(propertiesFile)) {
+        props.store(out, String.format("Temporary properties file for command [%s]", javaCommand.getProcessId().getKey()));
+      }
       return propertiesFile;
     } catch (Exception e) {
       throw new IllegalStateException("Cannot write temporary settings to " + propertiesFile, e);
index a65ad3d8d80b9acd4b4bb2b743da7237dfc10e4b..368e1f98aa397cee755fd86b90dba9e4cd31c74b 100644 (file)
@@ -44,19 +44,17 @@ public class ActivityIndexer extends BaseIndexer {
     BulkIndexer bulk = new BulkIndexer(esClient, ActivityIndexDefinition.INDEX);
     bulk.setLarge(lastUpdatedAt == 0L);
 
-    DbSession dbSession = dbClient.openSession(false);
-    try {
-      ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt);
+    try (
+      DbSession dbSession = dbClient.openSession(false);
+      ActivityResultSetIterator it = ActivityResultSetIterator.create(dbClient, dbSession, lastUpdatedAt)) {
+
       bulk.start();
       while (it.hasNext()) {
         bulk.add(it.next());
       }
       bulk.stop();
-      it.close();
       return it.getMaxRowDate();
 
-    } finally {
-      dbSession.close();
     }
   }
 
index 2bb86289c32ed5c2d1bdba5983a01bfd894a404f..2140aab032bc8e026adfbc085c4f2be2084c9635 100644 (file)
@@ -23,7 +23,6 @@ import org.junit.Test;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
 import org.sonar.scanner.bootstrap.BatchWsClient;
-import org.sonar.scanner.platform.DefaultServer;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;