Skip to content

Commit

Permalink
Reflectively check exception handler field to avoid breaking disrupto…
Browse files Browse the repository at this point in the history
…r 3.3.0

Co-authored-by: ags <[email protected]>
Co-authored-by: Daniel Milnes <[email protected]>
Co-authored-by: DJ <[email protected]>
  • Loading branch information
4 people committed Oct 16, 2024
1 parent 8e768b6 commit 6f892aa
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.lmax.tool.disruptor;

import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ExceptionHandlerWrapper;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -72,18 +71,23 @@ private void ensureDisruptorInstanceHasAnExceptionHandler(final Disruptor<?> dis
{
final Field field = Disruptor.class.getDeclaredField("exceptionHandler");
field.setAccessible(true);
Object exceptionHandler = field.get(disruptor);
if (exceptionHandler instanceof ExceptionHandlerWrapper)
{
final Field delegateField = ExceptionHandlerWrapper.class.getDeclaredField("delegate");
delegateField.setAccessible(true);
exceptionHandler = delegateField.get(exceptionHandler);
}
final Object exceptionHandler = field.get(disruptor);
if (exceptionHandler == null)
{
throw new IllegalStateException("Please supply an ExceptionHandler to the Disruptor instance. " +
"The default Disruptor behaviour is to stop processing when an exception occurs.");
}
if (exceptionHandler.getClass().getSimpleName().equals("com.lmax.disruptor.dsl.ExceptionHandlerWrapper"))
{
final Field delegateField = exceptionHandler.getClass().getDeclaredField("delegate");
delegateField.setAccessible(true);
final Object nestedExceptionHandler = delegateField.get(exceptionHandler);
if (nestedExceptionHandler == null)
{
throw new IllegalStateException("Please supply an ExceptionHandler to the Disruptor instance. " +
"The default Disruptor behaviour is to stop processing when an exception occurs.");
}
}
}
catch (NoSuchFieldException | IllegalAccessException e)
{
Expand Down

0 comments on commit 6f892aa

Please sign in to comment.