From df48d19bbc370f89b5aa0915640b9bc6c3e77a43 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Wed, 2 Jun 2021 16:50:03 +0100 Subject: [PATCH] HHH-14647 Make ResourceRegistryStandardImpl#unassociatedResultSets lazily initialized --- .../jdbc/internal/ResourceRegistryStandardImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java index 5c31b2f014..f8dbe76362 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/ResourceRegistryStandardImpl.java @@ -52,7 +52,7 @@ public final class ResourceRegistryStandardImpl implements ResourceRegistry { private final JdbcObserver jdbcObserver; private final HashMap> xref = new HashMap<>(); - private final HashMap unassociatedResultSets = new HashMap(); + private HashMap unassociatedResultSets; private ArrayList blobs; private ArrayList clobs; @@ -138,7 +138,7 @@ public final class ResourceRegistryStandardImpl implements ResourceRegistry { } } else { - final Object removed = unassociatedResultSets.remove( resultSet ); + final Object removed = unassociatedResultSets == null ? null : unassociatedResultSets.remove( resultSet ); if ( removed == null ) { log.unregisteredResultSetWithoutStatement(); } @@ -147,6 +147,9 @@ public final class ResourceRegistryStandardImpl implements ResourceRegistry { } private static void closeAll(final HashMap resultSets) { + if ( resultSets == null ) { + return; + } resultSets.forEach( (resultSet, o) -> close( resultSet ) ); resultSets.clear(); } @@ -234,6 +237,9 @@ public final class ResourceRegistryStandardImpl implements ResourceRegistry { resultSets.put( resultSet, PRESENT ); } else { + if ( unassociatedResultSets == null ) { + this.unassociatedResultSets = new HashMap(); + } unassociatedResultSets.put( resultSet, PRESENT ); } }