From 15dd898e39c213e04e7414d810d6b2b5b5382902 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Mon, 3 May 2021 07:58:00 -0500 Subject: [PATCH 1/2] gh-2329 - Prepare branch --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 526ad136a5..e27726e761 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-commons - 2.6.0-SNAPSHOT + 2.6.0-gh-2329-SNAPSHOT Spring Data Core From 48feb13d146080d4f231195533fbc616a8d188f0 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Mon, 3 May 2021 07:58:15 -0500 Subject: [PATCH 2/2] 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. --- .../context/AbstractMappingContext.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index f04bdd5ac3..d6755d1942 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -108,7 +108,8 @@ protected AbstractMappingContext() { this.persistentPropertyPathFactory = new PersistentPropertyPathFactory<>(this); EntityInstantiators instantiators = new EntityInstantiators(); - PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() ? BeanWrapperPropertyAccessorFactory.INSTANCE + PersistentPropertyAccessorFactory accessorFactory = NativeDetector.inNativeImage() + ? BeanWrapperPropertyAccessorFactory.INSTANCE : new ClassGeneratingPropertyAccessorFactory(); this.persistentPropertyAccessorFactory = new InstantiationAwarePropertyAccessorFactory(accessorFactory, @@ -378,25 +379,21 @@ protected Optional addPersistentEntity(TypeInformation typeInformation) { descriptors.put(descriptor.getName(), descriptor); } - try { - - PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors); - ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE); - persistentPropertyCreator.addPropertiesForRemainingDescriptors(); + PersistentPropertyCreator persistentPropertyCreator = new PersistentPropertyCreator(entity, descriptors); + ReflectionUtils.doWithFields(type, persistentPropertyCreator, PersistentPropertyFilter.INSTANCE); + persistentPropertyCreator.addPropertiesForRemainingDescriptors(); - entity.verify(); - - if (persistentPropertyAccessorFactory.isSupported(entity)) { - entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory); - } + entity.verify(); - } catch (RuntimeException e) { - persistentEntities.remove(typeInformation); - throw e; + if (persistentPropertyAccessorFactory.isSupported(entity)) { + entity.setPersistentPropertyAccessorFactory(persistentPropertyAccessorFactory); } } catch (BeansException e) { throw new MappingException(e.getMessage(), e); + } catch (RuntimeException e) { + persistentEntities.remove(typeInformation); + throw e; } finally { write.unlock(); }