From 70c35433f36cd2957f428f3197cae209a5daf39d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 26 Aug 2013 18:29:04 +0200 Subject: [PATCH] DATACMNS-362 - Resolved concurrency problem in Repositories. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now create a copy of the keys before iterating over them in Repositories.getRepoInforFor(…) to make sure other threads can safely trigger lookupRepositoryFactoryInformationFor(…) which potentially alters the repositories instance variable. So far we haven't guarded against this scenario which caused a ConcurrentModificationException. --- .../data/repository/support/Repositories.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/repository/support/Repositories.java b/src/main/java/org/springframework/data/repository/support/Repositories.java index 768d43ce3..65f2bdf0e 100644 --- a/src/main/java/org/springframework/data/repository/support/Repositories.java +++ b/src/main/java/org/springframework/data/repository/support/Repositories.java @@ -160,7 +160,10 @@ public class Repositories implements Iterable> { Assert.notNull(domainClass); - for (RepositoryFactoryInformation information : repositories.keySet()) { + // Create defensive copy of the keys to allow threads to potentially add values while iterating over them + Set> keys = Collections.unmodifiableSet(repositories.keySet()); + + for (RepositoryFactoryInformation information : keys) { if (domainClass.equals(information.getEntityInformation().getJavaType())) { return information; }