From 3e15ddb6e8b8d8195c3d2334bda43a53ffb593a7 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Mon, 16 Oct 2017 16:32:25 +0200 Subject: [PATCH] Fix quality flaws --- .../sonar/application/process/ProcessLauncherImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java b/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java index 3da6b18a0b7..181109a50c9 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/process/ProcessLauncherImpl.java @@ -42,6 +42,7 @@ import org.sonar.process.sharedmemoryfile.AllProcessesCommands; import org.sonar.process.sharedmemoryfile.ProcessCommands; import static java.lang.String.format; +import static java.util.Objects.requireNonNull; 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; @@ -142,7 +143,7 @@ public class ProcessLauncherImpl implements ProcessLauncher { } } - private Process launchJava(JavaCommand javaCommand) { + private Process launchJava(JavaCommand javaCommand) { ProcessId processId = javaCommand.getProcessId(); try { ProcessBuilder processBuilder = create(javaCommand); @@ -164,7 +165,9 @@ public class ProcessLauncherImpl implements ProcessLauncher { private ProcessBuilder create(EsScriptCommand esScriptCommand) { List commands = new ArrayList<>(); - commands.add(esScriptCommand.getEsInstallation().getExecutable().getAbsolutePath()); + EsInstallation esInstallation = esScriptCommand.getEsInstallation(); + requireNonNull(esInstallation, () -> "No Elasticsearch installation configuration is available for the command of type " + esScriptCommand.getClass()); + commands.add(esInstallation.getExecutable().getAbsolutePath()); commands.addAll(esScriptCommand.getOptions()); return create(esScriptCommand, commands); @@ -205,7 +208,7 @@ public class ProcessLauncherImpl implements ProcessLauncher { return new File(new File(System.getProperty("java.home")), "bin" + separator + "java").getAbsolutePath(); } - private static List buildClasspath(JavaCommand javaCommand) { + private static List buildClasspath(JavaCommand javaCommand) { String pathSeparator = System.getProperty("path.separator"); return Arrays.asList("-cp", String.join(pathSeparator, javaCommand.getClasspath())); } -- 2.39.5