diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu2Interceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu2Interceptor.java index c74fb12602f..bfb5d778c94 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu2Interceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu2Interceptor.java @@ -83,7 +83,12 @@ public class RestHookSubscriptionDstu2Interceptor extends BaseRestHookSubscripti * @param theOperation */ private void checkSubscriptions(IIdType idType, String resourceType, RestOperationTypeEnum theOperation) { - for (Subscription subscription : myRestHookSubscriptions) { + //avoid a ConcurrentModificationException by copying to an array + for (Object object : myRestHookSubscriptions.toArray()) { + if (object == null) { + continue; + } + Subscription subscription = (Subscription) object; // see if the criteria matches the created object ourLog.info("Checking subscription {} for {} with criteria {}", subscription.getIdElement().getIdPart(), resourceType, subscription.getCriteria()); @@ -121,6 +126,8 @@ public class RestHookSubscriptionDstu2Interceptor extends BaseRestHookSubscripti } } + + /** * Creates an HTTP Post for a subscription */ diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu3Interceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu3Interceptor.java index 0eda2bd28a2..ad53b7b8a67 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu3Interceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/RestHookSubscriptionDstu3Interceptor.java @@ -82,7 +82,13 @@ public class RestHookSubscriptionDstu3Interceptor extends BaseRestHookSubscripti * @param theOperation */ private void checkSubscriptions(IIdType idType, String resourceType, RestOperationTypeEnum theOperation) { - for (Subscription subscription : myRestHookSubscriptions) { + //avoid a ConcurrentModificationException by copying to an array + for (Object object : myRestHookSubscriptions.toArray()) { + //for (Subscription subscription : myRestHookSubscriptions) { + if (object == null) { + continue; + } + Subscription subscription = (Subscription) object; // see if the criteria matches the created object ourLog.info("Checking subscription {} for {} with criteria {}", subscription.getIdElement().getIdPart(), resourceType, subscription.getCriteria());