From 4fc5c8d3fe17a87d2dc6e14a4d1c153b2e06e3e0 Mon Sep 17 00:00:00 2001 From: Rabi Panda Date: Thu, 10 Nov 2022 13:48:41 -0800 Subject: [PATCH] Check for JDK version while setting java.security.manager option (#5205) Signed-off-by: Rabi Panda --- .../opensearch/gradle/OpenSearchTestBasePlugin.java | 5 ++++- .../opensearch/tools/launchers/SystemJvmOptions.java | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java index 4638cee1d96a6..67df8bbafcb03 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchTestBasePlugin.java @@ -109,7 +109,10 @@ public void execute(Task t) { test.systemProperty("java.locale.providers", "SPI,JRE"); } else { test.systemProperty("java.locale.providers", "SPI,COMPAT"); - test.jvmArgs("--illegal-access=warn", "-Djava.security.manager=allow"); + test.jvmArgs("--illegal-access=warn"); + } + if (test.getJavaVersion().compareTo(JavaVersion.VERSION_17) > 0) { + test.jvmArgs("-Djava.security.manager=allow"); } } }); diff --git a/distribution/tools/launchers/src/main/java/org/opensearch/tools/launchers/SystemJvmOptions.java b/distribution/tools/launchers/src/main/java/org/opensearch/tools/launchers/SystemJvmOptions.java index 30969a0df2a2c..aa3dfbe39ee96 100644 --- a/distribution/tools/launchers/src/main/java/org/opensearch/tools/launchers/SystemJvmOptions.java +++ b/distribution/tools/launchers/src/main/java/org/opensearch/tools/launchers/SystemJvmOptions.java @@ -78,12 +78,20 @@ static List systemJvmOptions() { "-Dlog4j.shutdownHookEnabled=false", "-Dlog4j2.disable.jmx=true", // security manager - "-Djava.security.manager=allow", + allowSecurityManagerOption(), javaLocaleProviders() ) ).stream().filter(e -> e.isEmpty() == false).collect(Collectors.toList()); } + private static String allowSecurityManagerOption() { + if (Runtime.version().feature() > 17) { + return "-Djava.security.manager=allow"; + } else { + return ""; + } + } + private static String maybeShowCodeDetailsInExceptionMessages() { if (Runtime.version().feature() >= 14) { return "-XX:+ShowCodeDetailsInExceptionMessages";