diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java index a6486608c77b..f1dea4a5e78d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/CollectionHelper.java @@ -343,6 +343,9 @@ public static Set toSmallSet(Set set) { * The goal is to save memory. */ public static Map toSmallMap(final Map map) { + if ( map == null ) { + return emptyMap(); + } return switch ( map.size() ) { case 0 -> emptyMap(); case 1 -> { @@ -363,6 +366,9 @@ public static Map toSmallMap(final Map map) { * The goal is to save memory. */ public static List toSmallList(ArrayList arrayList) { + if ( arrayList == null ) { + return emptyList(); + } return switch ( arrayList.size() ) { case 0 -> emptyList(); case 1 -> singletonList( arrayList.get( 0 ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 1af5735720e7..1ce0bbdd8bab 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -128,6 +128,8 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.makeCopy; +import static org.hibernate.internal.util.collections.CollectionHelper.toSmallList; +import static org.hibernate.internal.util.collections.CollectionHelper.toSmallMap; import static org.hibernate.internal.util.type.PrimitiveWrapperHelper.getDescriptorByPrimitiveType; import static org.hibernate.jpa.HibernateHints.HINT_NATIVE_LOCK_MODE; import static org.hibernate.query.results.internal.Builders.resultClassBuilder; @@ -1742,9 +1744,9 @@ private static class ParameterInterpretationImpl implements ParameterInterpretat public ParameterInterpretationImpl(ParameterRecognizerImpl parameterRecognizer) { this.sqlString = parameterRecognizer.getAdjustedSqlString(); - this.parameterList = parameterRecognizer.getParameterList(); - this.positionalParameters = parameterRecognizer.getPositionalQueryParameters(); - this.namedParameters = parameterRecognizer.getNamedQueryParameters(); + this.parameterList = toSmallList( parameterRecognizer.getParameterList() ); + this.positionalParameters = toSmallMap( parameterRecognizer.getPositionalQueryParameters() ); + this.namedParameters = toSmallMap( parameterRecognizer.getNamedQueryParameters() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ParameterRecognizerImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ParameterRecognizerImpl.java index d8561de73130..71b66daec418 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ParameterRecognizerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/ParameterRecognizerImpl.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.hibernate.QueryException; @@ -36,7 +35,7 @@ private enum ParameterStyle { private int ordinalParameterImplicitPosition; - private List parameterList; + private ArrayList parameterList; private final StringBuilder sqlStringBuffer = new StringBuilder(); public ParameterRecognizerImpl() { @@ -81,7 +80,7 @@ public Map> getPositionalQueryParameters() return positionalQueryParameters; } - public List getParameterList() { + public ArrayList getParameterList() { return parameterList; }