Skip to content

Commit eff296e

Browse files
committed
fix: correctly detect Disruptor major version
Ensure the Disruptor version is detected using the classloader that loaded `DisruptorUtil`, rather than the thread-context classloader. The previous implementation relied on `LoaderUtil.isClassAvailable`, which may fail in environments where the Disruptor classes aren't visible to the thread-context classloader.
1 parent 50a86c7 commit eff296e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,19 @@ final class DisruptorUtil {
5050
static final boolean ASYNC_CONFIG_SYNCHRONIZE_ENQUEUE_WHEN_QUEUE_FULL = PropertiesUtil.getProperties()
5151
.getBooleanProperty("AsyncLoggerConfig.SynchronizeEnqueueWhenQueueFull", true);
5252

53-
static final int DISRUPTOR_MAJOR_VERSION =
54-
LoaderUtil.isClassAvailable("com.lmax.disruptor.SequenceReportingEventHandler") ? 3 : 4;
53+
static final int DISRUPTOR_MAJOR_VERSION = detectDisruptorMajorVersion();
54+
55+
// TODO: replace with LoaderUtil.isClassAvailable() when TCCL is removed
56+
// See: https://github.com/apache/logging-log4j2/issues/3706
57+
private static int detectDisruptorMajorVersion() {
58+
try {
59+
Class.forName(
60+
"com.lmax.disruptor.SequenceReportingEventHandler", true, DisruptorUtil.class.getClassLoader());
61+
return 3;
62+
} catch (final ClassNotFoundException e) {
63+
return 4;
64+
}
65+
}
5566

5667
private DisruptorUtil() {}
5768

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="3706" link="https://github.com/apache/logging-log4j2/issues/3706"/>
9+
<description format="asciidoc">
10+
Fix detection of the Disruptor major version in some environments.
11+
</description>
12+
</entry>

0 commit comments

Comments
 (0)