Skip to content

Commit 2511b1f

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 17c8e7f commit 2511b1f

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
@@ -385,25 +385,21 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
385385
descriptors.put(descriptor.getName(), descriptor);
386386
}
387387

388-
try {
389-
390-
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
391-
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
392-
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
388+
PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors);
389+
ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE);
390+
persistentPropertyCreator.addPropertiesForRemainingDescriptors();
393391

394-
entity.verify();
395-
396-
if (persistentPropertyAccessorFactory.isSupported(entity)) {
397-
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
398-
}
392+
entity.verify();
399393

400-
} catch (RuntimeException e) {
401-
persistentEntities.remove(typeInformation);
402-
throw e;
394+
if (persistentPropertyAccessorFactory.isSupported(entity)) {
395+
entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory);
403396
}
404397

405398
} catch (BeansException e) {
406399
throw new MappingException(e.getMessage(), e);
400+
} catch (RuntimeException e) {
401+
persistentEntities.remove(typeInformation);
402+
throw e;
407403
} finally {
408404
write.unlock();
409405
}

0 commit comments

Comments
 (0)