From 5293cdd235d2cd13b592c64c1574157b3587b830 Mon Sep 17 00:00:00 2001 From: clement Date: Tue, 28 Mar 2023 14:16:59 +0200 Subject: [PATCH] HHH-16385 Ensure QueryKey is immutable and serializable --- .../src/main/java/org/hibernate/cache/spi/QueryKey.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/QueryKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/QueryKey.java index 86f10ecb61..f1704fe139 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/QueryKey.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/QueryKey.java @@ -8,6 +8,7 @@ package org.hibernate.cache.spi; import java.io.IOException; import java.io.Serializable; +import java.util.Arrays; import java.util.Objects; import java.util.Set; @@ -65,7 +66,7 @@ public class QueryKey implements Serializable { private final Integer firstRow; private final Integer maxRows; private final String tenantIdentifier; - private final Set enabledFilterNames; + private final String[] enabledFilterNames; /** * For performance reasons, the hashCode is cached; however, it is marked transient so that it can be @@ -85,7 +86,7 @@ public class QueryKey implements Serializable { this.firstRow = firstRow; this.maxRows = maxRows; this.tenantIdentifier = tenantIdentifier; - this.enabledFilterNames = enabledFilterNames; + this.enabledFilterNames = enabledFilterNames.toArray( String[]::new ); this.hashCode = generateHashCode(); } @@ -110,7 +111,7 @@ public class QueryKey implements Serializable { // result = 37 * result + ( maxRows==null ? 0 : maxRows ); result = 37 * result + ( tenantIdentifier==null ? 0 : tenantIdentifier.hashCode() ); result = 37 * result + parameterBindingsMemento.hashCode(); - result = 37 * result + ( enabledFilterNames == null ? 0 : enabledFilterNames.hashCode() ); + result = 37 * result + Arrays.hashCode( enabledFilterNames ); return result; } @@ -146,7 +147,7 @@ public class QueryKey implements Serializable { return false; } - if ( ! Objects.equals( enabledFilterNames, that.enabledFilterNames ) ) { + if ( ! Arrays.equals( enabledFilterNames, that.enabledFilterNames ) ) { return false; }