Skip to content

Commit 48feb13

Browse files
committed
Handle errors at a higher level.
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. See #2329.
1 parent 15dd898 commit 48feb13

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ protected AbstractMappingContext() {
108108
this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this);
109109

110110
EntityInstantiators instantiators = new EntityInstantiators();
111-
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() ? BeanWrapperPropertyAccessorFactory.INSTANCE
111+
PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage()
112+
? BeanWrapperPropertyAccessorFactory.INSTANCE
112113
: new ClassGeneratingPropertyAccessorFactory();
113114

114115
this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory,
@@ -378,25 +379,21 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
378379
descriptors.put(descriptor.getName(), descriptor);
379380
}
380381

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

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

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

398392
} catch (BeansException e) {
399393
throw new MappingException(e.getMessage(), e);
394+
} catch (RuntimeException e) {
395+
persistentEntities.remove(typeInformation);
396+
throw e;
400397
} finally {
401398
write.unlock();
402399
}

0 commit comments

Comments
 (0)