Avoid extra whitespace in parsed JVM options (#57769) (#62138)

The windows service script does a little munging of the parsed JVM
option string, converting whitespaces to semicolons. We recently added
an optional Java 14 JDK flag to our system JVM flags. On earlier JDKs,
the windows service batch script would encounter a double whitespace
when this option was missing and convert it into double semicolons.
Double semicolons, in turn, don't work in the arguments to the windows
service command, and led to a lot of JVM options being dropped,
including "es.path.conf", which is required for startup.

This commit puts in a double defense. First, it removes any empty-string
options from the system options list in the Java Options Parser code.
Second, it munges out double semicolons if they do appear in the parsed
option output.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
William Brafford 2020-09-09 09:51:12 -04:00 committed by GitHub
parent 1b9dc0172a
commit 8d8a918bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -121,6 +121,7 @@ rem - third, JVM options from ES_JAVA_OPTS are applied
rem - fourth, ergonomic JVM options are applied rem - fourth, ergonomic JVM options are applied
if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;% if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%
if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS:;;=;%
@setlocal @setlocal
for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set ES_JAVA_OPTS=%%a for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.JvmOptionsParser" "!ES_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set ES_JAVA_OPTS=%%a

View File

@ -24,6 +24,7 @@ import org.elasticsearch.tools.java_version_checker.JavaVersion;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
final class SystemJvmOptions { final class SystemJvmOptions {
@ -68,7 +69,7 @@ final class SystemJvmOptions {
javaLocaleProviders() javaLocaleProviders()
) )
); ).stream().filter(e -> e.isEmpty() == false).collect(Collectors.toList());
} }
private static String maybeShowCodeDetailsInExceptionMessages() { private static String maybeShowCodeDetailsInExceptionMessages() {