Skip to content

Commit

Permalink
Fix exception handler validation for modern disruptor versions
Browse files Browse the repository at this point in the history
Co-authored-by: ags <[email protected]>
Co-authored-by: DJ <[email protected]>
  • Loading branch information
3 people committed Oct 16, 2024
1 parent c40c039 commit 0a1a97a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 @@ -71,17 +72,20 @@ private void ensureDisruptorInstanceHasAnExceptionHandler(final Disruptor<?> dis
{
final Field field = Disruptor.class.getDeclaredField("exceptionHandler");
field.setAccessible(true);
if (field.get(disruptor) == null)
Object exceptionHandler = field.get(disruptor);
if (exceptionHandler instanceof ExceptionHandlerWrapper)
{
final Field delegateField = ExceptionHandlerWrapper.class.getDeclaredField("delegate");
delegateField.setAccessible(true);
exceptionHandler = delegateField.get(exceptionHandler);
}
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.");
}
}
catch (NoSuchFieldException e)
{
throw new RuntimeException("Unable to inspect Disruptor instance", e);
}
catch (IllegalAccessException e)
catch (NoSuchFieldException | IllegalAccessException e)
{
throw new RuntimeException("Unable to inspect Disruptor instance", e);
}
Expand Down

0 comments on commit 0a1a97a

Please sign in to comment.