From 8a1be49c0400dca00de644f1d04e7a9a1eccff54 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 26 Jan 2021 09:47:37 +0100 Subject: [PATCH] Guard potential null dereference in recursive initialization calls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now assign the repository field before resolving the persistent entity through the mapping context to avoid a potential NPE caused by a getObject(…) invocation through an application event. Closes #2068 --- .../repository/core/support/RepositoryFactoryBeanSupport.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java index 241ecad40..d44437fe5 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java @@ -320,11 +320,11 @@ public abstract class RepositoryFactoryBeanSupport, this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); + this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); + // Make sure the aggregate root type is present in the MappingContext (e.g. for auditing) this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType())); - this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); - if (!lazyInit) { this.repository.get(); }