Skip to content

Commit 80c3da6

Browse files
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
1 parent 3241bfc commit 80c3da6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ static void initializeProbes() {
160160
JvmInfo.jvmInfo();
161161
}
162162

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

@@ -211,6 +229,8 @@ public void run() {
211229
// Log ifconfig output before SecurityManager is installed
212230
IfConfig.logIfNecessary();
213231

232+
fixJDK14EAFileChannelMap();
233+
214234
// install SM after natives, shutdown hooks, etc.
215235
try {
216236
Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));

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

+2
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)