Skip to content

Commit 8a1be49

Browse files
committed
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 spring-projects#2068
1 parent 42997ac commit 8a1be49

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,11 @@ public void afterPropertiesSet() {
320320

321321
this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface);
322322

323+
this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse));
324+
323325
// Make sure the aggregate root type is present in the MappingContext (e.g. for auditing)
324326
this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType()));
325327

326-
this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse));
327-
328328
if (!lazyInit) {
329329
this.repository.get();
330330
}

0 commit comments

Comments
 (0)