Browse Source

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
pull/2285/head
Mark Paluch 5 years ago
parent
commit
3d7cabf814
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 4
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

4
src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

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

Loading…
Cancel
Save