Skip to content

Commit 7254ee5

Browse files
committed
DATAREST-723 - PropertyMappings now get eagerly initialized.
Switched to eager initialization of PropertyMappings to avoid potential ConcurrentModificationException.
1 parent db096c9 commit 7254ee5

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/MappingResourceMetadata.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,14 @@ public MappingResourceMetadata(PersistentEntity<?, ?> entity, ResourceMappings r
4949

5050
super(entity.getType());
5151

52-
this.entity = entity;
5352
this.propertyMappings = new PropertyMappings(resourceMappings);
5453

55-
RestResource annotation = entity.findAnnotation(RestResource.class);
56-
this.explicitlyExported = annotation != null && annotation.exported();
57-
}
58-
59-
public MappingResourceMetadata init() {
60-
54+
this.entity = entity;
6155
this.entity.doWithAssociations(propertyMappings);
6256
this.entity.doWithProperties(propertyMappings);
6357

64-
return this;
58+
RestResource annotation = entity.findAnnotation(RestResource.class);
59+
this.explicitlyExported = annotation != null && annotation.exported();
6560
}
6661

6762
/*

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/mapping/PersistentEntitiesResourceMappings.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ MappingResourceMetadata getMappingMetadataFor(Class<?> type) {
9999

100100
mappingMetadata = new MappingResourceMetadata(entity, this);
101101
mappingCache.put(type, mappingMetadata);
102-
mappingMetadata.init();
103-
104102
return mappingMetadata;
105103
}
106104

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/mapping/MappingResourceMetadataUnitTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public class MappingResourceMetadataUnitTests {
4141
MongoMappingContext context = new MongoMappingContext();
4242

4343
MongoPersistentEntity<?> entity = context.getPersistentEntity(Entity.class);
44-
ResourceMappings resourceMappings = new PersistentEntitiesResourceMappings(new PersistentEntities(
45-
Arrays.asList(context)));
46-
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings).init();
44+
ResourceMappings resourceMappings = new PersistentEntitiesResourceMappings(
45+
new PersistentEntities(Arrays.asList(context)));
46+
MappingResourceMetadata metadata = new MappingResourceMetadata(entity, resourceMappings);
4747

4848
/**
4949
* @see DATAREST-514
@@ -76,7 +76,7 @@ public void isNotExportedByDefault() {
7676
public void isExportedIfExplicitlyAnnotated() {
7777

7878
MappingResourceMetadata metadata = new MappingResourceMetadata(context.getPersistentEntity(Related.class),
79-
resourceMappings).init();
79+
resourceMappings);
8080
assertThat(metadata.isExported(), is(true));
8181
}
8282

0 commit comments

Comments
 (0)