From d6e543a478e2b061da45959b100a699ec7e1bdc9 Mon Sep 17 00:00:00 2001 From: jmarchionatto <60409882+jmarchionatto@users.noreply.github.com> Date: Mon, 13 Dec 2021 08:14:28 -0500 Subject: [PATCH] Loop over new list to avoid ConcurrentModificationException in case a new hook is added while looping (#3233) Co-authored-by: juan.marchionatto --- .../uhn/fhir/interceptor/executor/BaseInterceptorService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/BaseInterceptorService.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/BaseInterceptorService.java index e2b3adacb3c..57dc1a79da5 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/BaseInterceptorService.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/interceptor/executor/BaseInterceptorService.java @@ -291,7 +291,8 @@ public abstract class BaseInterceptorService impleme } private Object doCallHooks(POINTCUT thePointcut, HookParams theParams, Object theRetVal) { - List invokers = getInvokersForPointcut(thePointcut); + // use new list for loop to avoid ConcurrentModificationException in case invoker gets added while looping + List invokers = new ArrayList<>(getInvokersForPointcut(thePointcut)); /* * Call each hook in order