Skip to content

Commit

Permalink
Fix ClassCastException in LMAX Disruptor 3 initialization (#2768)
Browse files Browse the repository at this point in the history
Co-authored-by: Volkan Yazıcı <[email protected]>
Co-authored-by: Piotr P. Karwasz <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2024
1 parent 132deb2 commit 0896015
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
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
Expand All @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/changelog/.2.x.x/fix_disruptor3_cce.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 0896015

Please sign in to comment.