Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/92377.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 92377
summary: Force init of Unbox in log4j
area: Infra/Core
type: bug
issues:
- 91964
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.logging.log4j.status.StatusData;
import org.apache.logging.log4j.status.StatusListener;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.util.Unbox;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.logging.internal.LoggerFactoryImpl;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -41,6 +42,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
Expand Down Expand Up @@ -122,6 +124,7 @@ public static void configure(final Environment environment, boolean useConsole)
}
configureESLogging();
configure(environment.settings(), environment.configFile(), environment.logsFile(), useConsole);
initializeStatics();
}

public static void configureESLogging() {
Expand All @@ -144,6 +147,17 @@ public static void setNodeName(String nodeName) {
NodeNamePatternConverter.setNodeName(nodeName);
}

// Some classes within log4j have static initializers that require security manager permissions.
// Here we aggressively initialize those classes during logging configuration so that
// actual logging calls at runtime do not trigger that initialization.
private static void initializeStatics() {
try {
MethodHandles.publicLookup().ensureInitialized(Unbox.class);
} catch (IllegalAccessException impossible) {
throw new AssertionError(impossible);
}
}

private static void checkErrorListener() {
assert errorListenerIsRegistered() : "expected error listener to be registered";
if (error.get()) {
Expand Down