Skip to content

Commit b05965f

Browse files
gregturnmp911de
authored andcommitted
Remove PersistentEntity from MappingContext upon mapping metadata initialization errors.
When an error happens inside the AbstractMappingContext, the caching sometimes gets corrupted. That's because some exceptions are caught, others are not. Instead, the error handling that clears out the cache needs to be shifted up one level, resulting in a simpler code block. Closes #2329 Original pull request: #2367.
1 parent edc7153 commit b05965f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,21 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
378378
descriptors.put(descriptor.getName(), descriptor);
379379
}
380380

381-
try {
382-
383-
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
384-
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
385-
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
381+
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
382+
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
383+
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
386384

387-
entity.verify();
388-
389-
if (persistentPropertyAccessorFactory.isSupported(entity)) {
390-
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
391-
}
385+
entity.verify();
392386

393-
} catch (RuntimeException e) {
394-
persistentEntities.remove(typeInformation);
395-
throw e;
387+
if (persistentPropertyAccessorFactory.isSupported(entity)) {
388+
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
396389
}
397390

398391
} catch (BeansException e) {
399392
throw new MappingException(e.getMessage(), e);
393+
} catch (RuntimeException e) {
394+
persistentEntities.remove(typeInformation);
395+
throw e;
400396
} finally {
401397
write.unlock();
402398
}

0 commit comments

Comments
 (0)