Guard potential null dereference in recursive initialization calls.

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
This commit is contained in:
Mark Paluch
2021-01-26 09:47:37 +01:00
parent 89c5b3839c
commit 3d7cabf814

View File

@@ -320,11 +320,11 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
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();
}