From 7ee541546a7a7db88028b526355120f0c5153a80 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 9 May 2019 09:19:30 -0400 Subject: [PATCH] Account for Java 8 in JVM options parsing Java 8 presents the JVM options slightly differently when displaying via -XX:+PrintFlagsFinal. This commit adapts the JVM options parser for this possibility. Relates #42009 --- .../org/elasticsearch/tools/launchers/JvmErgonomics.java | 2 +- .../elasticsearch/tools/launchers/JvmErgonomicsTests.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java index 44f60ba2d9f..e0e6632aa24 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/JvmErgonomics.java @@ -68,7 +68,7 @@ final class JvmErgonomics { } private static final Pattern OPTION = - Pattern.compile("^\\s*\\S+\\s+(?\\S+)\\s+:?=\\s+(?\\S+)?\\s+\\{[^}]+?\\}\\s+\\{[^}]+}"); + Pattern.compile("^\\s*\\S+\\s+(?\\S+)\\s+:?=\\s+(?\\S+)?\\s+\\{[^}]+?\\}(\\s+\\{[^}]+})?"); static Map> finalJvmOptions( final List userDefinedJvmOptions) throws InterruptedException, IOException { diff --git a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java index b5b6699f471..c24cbdb097b 100644 --- a/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java +++ b/distribution/tools/launchers/src/test/java/org/elasticsearch/tools/launchers/JvmErgonomicsTests.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -71,7 +72,9 @@ public class JvmErgonomicsTests extends LaunchersTestCase { fail("expected starting java to fail"); } catch (final RuntimeException e) { assertThat(e, hasToString(containsString(("starting java failed")))); - assertThat(e, hasToString(containsString(("Too small maximum heap")))); + assertThat( + e, + anyOf(hasToString(containsString("Too small initial heap")), hasToString(containsString("Too small maximum heap")))); } }