Skip to content

Commit 0896015

Browse files
jackshirazivyppkarwasz
authored
Fix ClassCastException in LMAX Disruptor 3 initialization (#2768)
Co-authored-by: Volkan Yazıcı <[email protected]> Co-authored-by: Piotr P. Karwasz <[email protected]>
1 parent 132deb2 commit 0896015

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.logging.log4j.core.util.Log4jThreadFactory;
3737
import org.apache.logging.log4j.core.util.Throwables;
3838
import org.apache.logging.log4j.message.Message;
39-
import org.apache.logging.log4j.util.LoaderUtil;
4039

4140
/**
4241
* Helper class for async loggers: AsyncLoggerDisruptor handles the mechanics of working with the LMAX Disruptor, and
@@ -54,7 +53,11 @@ class AsyncLoggerDisruptor extends AbstractLifeCycle {
5453
private static EventHandler<RingBufferLogEvent> createEventHandler() {
5554
if (DisruptorUtil.DISRUPTOR_MAJOR_VERSION == 3) {
5655
try {
57-
return LoaderUtil.newInstanceOf("org.apache.logging.log4j.core.async.RingBufferLogEventHandler");
56+
return (EventHandler<RingBufferLogEvent>)
57+
// Avoid using `LoaderUtil`, which might choose an incorrect class loader – see #2768.
58+
Class.forName("org.apache.logging.log4j.core.async.RingBufferLogEventHandler")
59+
.getConstructor()
60+
.newInstance();
5861
} catch (final ReflectiveOperationException | LinkageError e) {
5962
LOGGER.warn("Failed to create event handler for LMAX Disruptor 3.x, trying version 4.x.", e);
6063
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="fixed">
6+
<issue id="2768" link="https://github.com/apache/logging-log4j2/pull/2768"/>
7+
<description format="asciidoc">Fix `ClassCastException` in LMAX Disruptor 3 initialization</description>
8+
</entry>

0 commit comments

Comments
 (0)