This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 089601576f Fix `ClassCastException` in LMAX Disruptor 3 initialization 
(#2768)
089601576f is described below

commit 089601576f94198d9edde51a311a09139cc67eb9
Author: jackshirazi <[email protected]>
AuthorDate: Fri Jul 26 20:05:12 2024 +0100

    Fix `ClassCastException` in LMAX Disruptor 3 initialization (#2768)
    
    Co-authored-by: Volkan Yazıcı <[email protected]>
    Co-authored-by: Piotr P. Karwasz <[email protected]>
---
 .../org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java | 7 +++++--
 src/changelog/.2.x.x/fix_disruptor3_cce.xml                       | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
index 7b6b0d8dc1..122b7af60b 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
@@ -36,7 +36,6 @@ import org.apache.logging.log4j.core.util.Log4jThread;
 import org.apache.logging.log4j.core.util.Log4jThreadFactory;
 import org.apache.logging.log4j.core.util.Throwables;
 import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.util.LoaderUtil;
 
 /**
  * Helper class for async loggers: AsyncLoggerDisruptor handles the mechanics 
of working with the LMAX Disruptor, and
@@ -54,7 +53,11 @@ class AsyncLoggerDisruptor extends AbstractLifeCycle {
     private static EventHandler<RingBufferLogEvent> createEventHandler() {
         if (DisruptorUtil.DISRUPTOR_MAJOR_VERSION == 3) {
             try {
-                return 
LoaderUtil.newInstanceOf("org.apache.logging.log4j.core.async.RingBufferLogEventHandler");
+                return (EventHandler<RingBufferLogEvent>)
+                        // Avoid using `LoaderUtil`, which might choose an 
incorrect class loader – see #2768.
+                        
Class.forName("org.apache.logging.log4j.core.async.RingBufferLogEventHandler")
+                                .getConstructor()
+                                .newInstance();
             } catch (final ReflectiveOperationException | LinkageError e) {
                 LOGGER.warn("Failed to create event handler for LMAX Disruptor 
3.x, trying version 4.x.", e);
             }
diff --git a/src/changelog/.2.x.x/fix_disruptor3_cce.xml 
b/src/changelog/.2.x.x/fix_disruptor3_cce.xml
new file mode 100644
index 0000000000..23d425a818
--- /dev/null
+++ b/src/changelog/.2.x.x/fix_disruptor3_cce.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="2768" link="https://github.com/apache/logging-log4j2/pull/2768"/>
+  <description format="asciidoc">Fix `ClassCastException` in LMAX Disruptor 3 
initialization</description>
+</entry>

Reply via email to