From 1ed1167153fe3717e72e3a064bcde934304416fe Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 2 Sep 2015 16:55:09 +0200 Subject: [PATCH] Avoid ConcurrentModificationException in SingleConnectionFactory's AggregatedExceptionListener Issue: SPR-13421 --- .../jms/connection/SingleConnectionFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index c3cf003f20b..05c28ae6efb 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -667,7 +667,9 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti @Override public void onException(JMSException ex) { synchronized (connectionMonitor) { - for (ExceptionListener listener : this.delegates) { + // Iterate over temporary copy in order to avoid ConcurrentModificationException, + // since listener invocations may in turn trigger registration of listeners... + for (ExceptionListener listener : new LinkedHashSet(this.delegates)) { listener.onException(ex); } }