From 0a1a97ae63eff27f862aae19f9f30a4dbf682cfb Mon Sep 17 00:00:00 2001 From: cooked Date: Wed, 16 Oct 2024 11:09:48 +0100 Subject: [PATCH] Fix exception handler validation for modern disruptor versions Co-authored-by: ags Co-authored-by: DJ --- .../tool/disruptor/ConfigurableValidator.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java b/src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java index e602a83..1bf8230 100644 --- a/src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java +++ b/src/main/java/com/lmax/tool/disruptor/ConfigurableValidator.java @@ -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; @@ -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); }