DATACMNS-390 - Create defensive copy for persistent entities in AbstractMappingContext.
To prevent ConcurrentModificationExceptions when iterating over PersistentEntities while further entity types are potentially added to the MappingContext we now return a immutable defensive copy of the current entity set.
This commit is contained in:
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.*;
|
||||
import groovy.lang.MetaClass;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.mapping.model.BasicPersistentEntity;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
|
||||
/**
|
||||
@@ -193,6 +195,24 @@ public class AbstractMappingContextUnitTests {
|
||||
context.getPersistentPropertyPath("foo", Sample.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-390
|
||||
*/
|
||||
@Test
|
||||
public void exposesCopyOfPersistentEntitiesToAvoidConcurrentModificationException() {
|
||||
|
||||
SampleMappingContext context = new SampleMappingContext();
|
||||
context.getPersistentEntity(ClassTypeInformation.MAP);
|
||||
|
||||
Iterator<BasicPersistentEntity<Object, SamplePersistentProperty>> iterator = context.getPersistentEntities()
|
||||
.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
context.getPersistentEntity(ClassTypeInformation.SET);
|
||||
iterator.next();
|
||||
}
|
||||
}
|
||||
|
||||
class Person {
|
||||
String name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user