Skip to content

Commit 3fc0851

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 #2068
1 parent 07dad67 commit 3fc0851

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ public void afterPropertiesSet() {
291291

292292
this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface);
293293

294+
this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse));
295+
294296
// Make sure the aggregate root type is present in the MappingContext (e.g. for auditing)
295297
this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType()));
296298

297-
this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse));
298-
299299
if (!lazyInit) {
300300
this.repository.get();
301301
}

0 commit comments

Comments
 (0)