Skip to content

Commit c7fd24c

Browse files
Workaround for JDK 14 EA FileChannel.map issue (elastic#50523)
FileChannel.map provokes static initialization of ExtendedMapMode in JDK14 EA, which needs elevated privileges. Relates elastic#50512
1 parent 604172e commit c7fd24c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919

2020
package org.elasticsearch.bootstrap;
2121

22-
import org.apache.logging.log4j.Logger;
2322
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.Logger;
2424
import org.apache.logging.log4j.core.Appender;
2525
import org.apache.logging.log4j.core.LoggerContext;
2626
import org.apache.logging.log4j.core.appender.ConsoleAppender;
2727
import org.apache.logging.log4j.core.config.Configurator;
2828
import org.apache.lucene.util.Constants;
29-
import org.elasticsearch.core.internal.io.IOUtils;
3029
import org.apache.lucene.util.StringHelper;
3130
import org.elasticsearch.ElasticsearchException;
3231
import org.elasticsearch.Version;
@@ -41,6 +40,7 @@
4140
import org.elasticsearch.common.settings.SecureSettings;
4241
import org.elasticsearch.common.settings.Settings;
4342
import org.elasticsearch.common.transport.BoundTransportAddress;
43+
import org.elasticsearch.core.internal.io.IOUtils;
4444
import org.elasticsearch.env.Environment;
4545
import org.elasticsearch.monitor.jvm.JvmInfo;
4646
import org.elasticsearch.monitor.os.OsProbe;
@@ -158,6 +158,24 @@ static void initializeProbes() {
158158
JvmInfo.jvmInfo();
159159
}
160160

161+
/**
162+
* JDK 14 bug:
163+
* https://github.com/elastic/elasticsearch/issues/50512
164+
* We circumvent it here by loading the offending class before installing security manager.
165+
*
166+
* To be removed once the JDK is fixed.
167+
*/
168+
static void fixJDK14EAFileChannelMap() {
169+
// minor time-bomb here to ensure that we reevaluate if final 14 version does not include fix.
170+
if (System.getProperty("java.version").equals("14-ea")) {
171+
try {
172+
Class.forName("jdk.internal.misc.ExtendedMapMode", true, Bootstrap.class.getClassLoader());
173+
} catch (ClassNotFoundException e) {
174+
throw new RuntimeException("Unable to lookup ExtendedMapMode class", e);
175+
}
176+
}
177+
}
178+
161179
private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
162180
Settings settings = environment.settings();
163181

@@ -209,6 +227,8 @@ public void run() {
209227
// Log ifconfig output before SecurityManager is installed
210228
IfConfig.logIfNecessary();
211229

230+
fixJDK14EAFileChannelMap();
231+
212232
// install SM after natives, shutdown hooks, etc.
213233
try {
214234
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));

test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public class BootstrapForTesting {
102102
// Log ifconfig output before SecurityManager is installed
103103
IfConfig.logIfNecessary();
104104

105+
Bootstrap.fixJDK14EAFileChannelMap();
106+
105107
// install security manager if requested
106108
if (systemPropertyAsBoolean("tests.security.manager", true)) {
107109
try {

0 commit comments

Comments
 (0)