DATACMNS-362 - Resolved concurrency problem in Repositories.

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.
This commit is contained in:
Oliver Gierke
2013-08-26 18:29:04 +02:00
parent 0ed3fb774e
commit 1976878bd5

View File

@@ -173,7 +173,10 @@ public class Repositories implements Iterable<Class<?>> {
Assert.notNull(domainClass);
for (RepositoryFactoryInformation<Object, Serializable> information : repositories.keySet()) {
// Create defensive copy of the keys to allow threads to potentially add values while iterating over them
Set<RepositoryFactoryInformation<Object, Serializable>> keys = Collections.unmodifiableSet(repositories.keySet());
for (RepositoryFactoryInformation<Object, Serializable> information : keys) {
if (domainClass.equals(information.getEntityInformation().getJavaType())) {
return information;
}