]> source.dussan.org Git - sonarqube.git/commitdiff
use try-with-ressource to write log4j ES properties
authorMalena Ebert <63863184+malena-ebert-sonarsource@users.noreply.github.com>
Fri, 18 Sep 2020 06:34:50 +0000 (08:34 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Sep 2020 20:06:40 +0000 (20:06 +0000)
Co-authored-by: Pierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com>
server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java

index 128816433bcbc7f9d032f99c9d7eb127425f9fa5..9c9dee7581061d634c0f7bf1b0f901ec485cde6d 100644 (file)
@@ -50,10 +50,10 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.lang.String.format;
 import static java.util.Collections.singleton;
 import static java.util.Objects.requireNonNull;
+import static org.sonar.process.ProcessEntryPoint.PROPERTY_GRACEFUL_STOP_TIMEOUT_MS;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_KEY;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
-import static org.sonar.process.ProcessEntryPoint.PROPERTY_GRACEFUL_STOP_TIMEOUT_MS;
 
 public class ProcessLauncherImpl implements ProcessLauncher {
   private static final Logger LOG = LoggerFactory.getLogger(ProcessLauncherImpl.class);
@@ -148,10 +148,10 @@ public class ProcessLauncherImpl implements ProcessLauncher {
       throw new IllegalStateException(error);
     }
 
-    try {
-      esInstallation.getEsYmlSettings().writeToYmlSettingsFile(esInstallation.getElasticsearchYml());
-      esInstallation.getEsJvmOptions().writeToJvmOptionFile(esInstallation.getJvmOptions());
-      esInstallation.getLog4j2Properties().store(new FileOutputStream(esInstallation.getLog4j2PropertiesLocation()), "log4j2 properties file for ES bundled in SonarQube");
+    esInstallation.getEsYmlSettings().writeToYmlSettingsFile(esInstallation.getElasticsearchYml());
+    esInstallation.getEsJvmOptions().writeToJvmOptionFile(esInstallation.getJvmOptions());
+    try (FileOutputStream fileOutputStream = new FileOutputStream(esInstallation.getLog4j2PropertiesLocation())) {
+      esInstallation.getLog4j2Properties().store(fileOutputStream, "log4j2 properties file for ES bundled in SonarQube");
     } catch (IOException e) {
       throw new IllegalStateException("Failed to write ES configuration files", e);
     }