Workaround for JDK 14 EA FileChannel.map issue (#50523)

FileChannel.map provokes static initialization of ExtendedMapMode in
JDK14 EA, which needs elevated privileges.

Relates #50512
This commit is contained in:
Henning Andersen 2020-01-06 12:18:12 +01:00 committed by Henning Andersen
parent 9ae3cd2a78
commit 312bf44601
2 changed files with 22 additions and 0 deletions

View File

@ -160,6 +160,24 @@ final class Bootstrap {
JvmInfo.jvmInfo();
}
/**
* JDK 14 bug:
* https://github.com/elastic/elasticsearch/issues/50512
* We circumvent it here by loading the offending class before installing security manager.
*
* To be removed once the JDK is fixed.
*/
static void fixJDK14EAFileChannelMap() {
// minor time-bomb here to ensure that we reevaluate if final 14 version does not include fix.
if (System.getProperty("java.version").equals("14-ea")) {
try {
Class.forName("jdk.internal.misc.ExtendedMapMode", true, Bootstrap.class.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to lookup ExtendedMapMode class", e);
}
}
}
private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
Settings settings = environment.settings();
@ -211,6 +229,8 @@ final class Bootstrap {
// Log ifconfig output before SecurityManager is installed
IfConfig.logIfNecessary();
fixJDK14EAFileChannelMap();
// install SM after natives, shutdown hooks, etc.
try {
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));

View File

@ -102,6 +102,8 @@ public class BootstrapForTesting {
// Log ifconfig output before SecurityManager is installed
IfConfig.logIfNecessary();
Bootstrap.fixJDK14EAFileChannelMap();
// install security manager if requested
if (systemPropertyAsBoolean("tests.security.manager", true)) {
try {