You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2025/06/25 08:11:23 UTC
(logging-log4j2) 01/01: fix: correctly detect Disruptor major version
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch fix/3706_disruptor-tccl
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit eff296eb591eae0f16c460f9db92d846559c94b6
Author: Piotr P. Karwasz <pk...@apache.org>
AuthorDate: Wed Jun 25 10:00:41 2025 +0200
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.
---
.../apache/logging/log4j/core/async/DisruptorUtil.java | 15 +++++++++++++--
src/changelog/.2.x.x/3706_disruptor-tccl.xml | 12 ++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java
index bdd21bd4ef..f115e2ae37 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java
@@ -50,8 +50,19 @@ final class DisruptorUtil {
static final boolean ASYNC_CONFIG_SYNCHRONIZE_ENQUEUE_WHEN_QUEUE_FULL = PropertiesUtil.getProperties()
.getBooleanProperty("AsyncLoggerConfig.SynchronizeEnqueueWhenQueueFull", true);
- static final int DISRUPTOR_MAJOR_VERSION =
- LoaderUtil.isClassAvailable("com.lmax.disruptor.SequenceReportingEventHandler") ? 3 : 4;
+ static final int DISRUPTOR_MAJOR_VERSION = detectDisruptorMajorVersion();
+
+ // TODO: replace with LoaderUtil.isClassAvailable() when TCCL is removed
+ // See: https://github.com/apache/logging-log4j2/issues/3706
+ private static int detectDisruptorMajorVersion() {
+ try {
+ Class.forName(
+ "com.lmax.disruptor.SequenceReportingEventHandler", true, DisruptorUtil.class.getClassLoader());
+ return 3;
+ } catch (final ClassNotFoundException e) {
+ return 4;
+ }
+ }
private DisruptorUtil() {}
diff --git a/src/changelog/.2.x.x/3706_disruptor-tccl.xml b/src/changelog/.2.x.x/3706_disruptor-tccl.xml
new file mode 100644
index 0000000000..a6a446fb14
--- /dev/null
+++ b/src/changelog/.2.x.x/3706_disruptor-tccl.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ https://logging.apache.org/xml/ns
+ https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+ type="fixed">
+ <issue id="3706" link="https://github.com/apache/logging-log4j2/issues/3706"/>
+ <description format="asciidoc">
+ Fix detection of the Disruptor major version in some environments.
+ </description>
+</entry>