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 07dad67c38
commit 3fc08514b6

View File

@@ -291,11 +291,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();
}