From 44719e9bb22cae8847f0720b66477d24337948ff Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 9 Mar 2021 18:38:20 -0500 Subject: [PATCH] Avoid NPE when resolving collection key for delayed collections --- .../collection/internal/DelayedCollectionInitializer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java index 18c24c2a79..6f706c25e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java @@ -76,7 +76,9 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer // LoggingHelper.toLoggableString( getNavigablePath(), this.collectionKey.getKey() ) // ); // } - parentAccess.registerResolutionListener( owner -> collectionInstance.setOwner( owner ) ); + if ( collectionInstance != null ) { + parentAccess.registerResolutionListener( owner -> collectionInstance.setOwner( owner ) ); + } } else { final Object parentKey = parentAccess.getParentKey(); @@ -85,7 +87,9 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer collectionAttributeMapping.getCollectionDescriptor(), parentKey ); - parentAccess.registerResolutionListener( owner -> collectionInstance.setOwner( owner ) ); + if ( collectionInstance != null ) { + parentAccess.registerResolutionListener( owner -> collectionInstance.setOwner( owner ) ); + } } } }