diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java index 6199fea5cc..cfb2826243 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java @@ -11,11 +11,9 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import org.hibernate.EntityMode; -import org.hibernate.boot.MappingException; import org.hibernate.boot.jaxb.Origin; import org.hibernate.boot.jaxb.hbm.spi.EntityInfo; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmEntityBaseDefinition; @@ -46,7 +44,6 @@ import org.hibernate.boot.model.source.spi.SubclassEntitySource; import org.hibernate.boot.model.source.spi.ToolingHintContext; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.internal.util.compare.EqualsHelper; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java index d293d6f0f2..28b3a83480 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java @@ -7,12 +7,12 @@ package org.hibernate.bytecode.enhance.internal.bytebuddy; import java.util.Collection; +import java.util.Objects; import javax.persistence.Embedded; import javax.persistence.EmbeddedId; import javax.persistence.Id; import org.hibernate.bytecode.enhance.spi.EnhancerConstants; -import org.hibernate.internal.util.compare.EqualsHelper; import net.bytebuddy.ClassFileVersion; import net.bytebuddy.asm.Advice; @@ -125,8 +125,8 @@ class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppender { else { methodVisitor.visitMethodInsn( Opcodes.INVOKESTATIC, - Type.getInternalName( EqualsHelper.class ), - "areEqual", + Type.getInternalName( Objects.class ), + "deepEquals", Type.getMethodDescriptor( Type.getType( boolean.class ), Type.getType( Object.class ), Type.getType( Object.class ) ), false ); diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/javassist/AttributeTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/javassist/AttributeTypeDescriptor.java index 6193b68567..ab912c6c94 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/javassist/AttributeTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/javassist/AttributeTypeDescriptor.java @@ -15,9 +15,7 @@ import javassist.CtClass; import javassist.CtField; import javassist.NotFoundException; -import org.hibernate.bytecode.enhance.spi.EnhancementContext; import org.hibernate.bytecode.enhance.spi.EnhancerConstants; -import org.hibernate.internal.util.compare.EqualsHelper; /** * utility class to generate interceptor methods @@ -66,8 +64,7 @@ public abstract class AttributeTypeDescriptor { } builder.append( String.format( - " if ( !%s.areEqual( %s, $1 ) )", - EqualsHelper.class.getName(), + " if ( !Objects.deepEquals( %s, $1 ) )", readFragment ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java index cdb05cc1a8..9d14568218 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java @@ -12,6 +12,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import javax.persistence.PersistenceException; @@ -43,7 +44,6 @@ import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; -import org.hibernate.type.descriptor.java.StringTypeDescriptor; /** * @author Steve Ebersole @@ -108,7 +108,7 @@ public class EnabledCaching implements CacheImplementor, DomainDataRegionBuildin final DomainDataRegion region = getRegionFactory().buildDomainDataRegion( regionConfig, this ); regionsByName.put( region.getName(), region ); - if ( !StringTypeDescriptor.INSTANCE.areEqual( region.getName(), regionConfig.getRegionName() ) ) { + if ( ! Objects.equals( region.getName(), regionConfig.getRegionName() ) ) { throw new HibernateException( String.format( Locale.ROOT, diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java deleted file mode 100644 index 69cbe63133..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/compare/EqualsHelper.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal.util.compare; - -import java.util.Arrays; - -/** - * Helper for equality determination - * - * @author Gavin King - * @author Steve Ebersole - */ -public final class EqualsHelper { - - /** - * Like the legacy {@link #equals} method, but handles array-specific checks - * - * @param x One value to check - * @param y The other value - * - * @return {@code true} if the 2 values are equal; {@code false} otherwise. - */ - public static boolean areEqual(final Object x, final Object y) { - if ( x == y ) { - return true; - } - - if ( x == null || y == null ) { - // One is null, but the other is not (otherwise the `x == y` check would have passed). - // null can never equal a non-null - return false; - } - - if ( x.equals( y ) ) { - return true; - } - - // Check for possibility of arrays - final Class xClass = x.getClass(); - final Class yClass = y.getClass(); - - if ( xClass.isArray() && yClass.isArray() ) { - if ( xClass.equals( yClass ) ) { - if ( x instanceof boolean[] ) { - return Arrays.equals( (boolean[]) x, (boolean[]) y ); - } - else if ( x instanceof byte[] ) { - return Arrays.equals( (byte[]) x, (byte[]) y ); - } - else if ( x instanceof char[] ) { - return Arrays.equals( (char[]) x, (char[]) y ); - } - else if ( x instanceof short[] ) { - return Arrays.equals( (short[]) x, (short[]) y ); - } - else if ( x instanceof int[] ) { - return Arrays.equals( (int[]) x, (int[]) y ); - } - else if ( x instanceof long[] ) { - return Arrays.equals( (long[]) x, (long[]) y ); - } - else if ( x instanceof double[] ) { - return Arrays.equals( (double[]) x, (double[]) y ); - } - else if ( x instanceof float[] ) { - return Arrays.equals( (float[]) x, (float[]) y ); - } - } - return Arrays.equals( (Object[]) x, (Object[]) y ); - } - - return false; - } - - /** - * Private ctor - disallow instantiation - */ - private EqualsHelper() { - // disallow instantiation - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java index bf8c81e456..b0c407c0d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaTypeDescriptor.java @@ -8,9 +8,9 @@ package org.hibernate.type.descriptor.java; import java.io.Serializable; import java.util.Comparator; +import java.util.Objects; import org.hibernate.internal.util.compare.ComparableComparator; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.type.descriptor.WrapperOptions; /** @@ -75,7 +75,7 @@ public interface JavaTypeDescriptor extends Serializable { * @return True if the two are considered equal; false otherwise. */ default boolean areEqual(T one, T another) { - return EqualsHelper.areEqual( one, another ); + return Objects.deepEquals( one, another ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java index 90fdafaf2b..8e0ecae98b 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/SerializableTypeDescriptor.java @@ -11,6 +11,7 @@ import java.io.InputStream; import java.io.Serializable; import java.sql.Blob; import java.sql.SQLException; +import java.util.Arrays; import org.hibernate.HibernateException; import org.hibernate.annotations.Immutable; @@ -71,7 +72,7 @@ public class SerializableTypeDescriptor extends Abstract return false; } return one.equals( another ) - || PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual( toBytes( one ), toBytes( another ) ); + || Arrays.equals( toBytes( one ), toBytes( another ) ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java b/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java index 1e2fd00f94..98f12c2e37 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cache/RegionNameTest.java @@ -21,7 +21,6 @@ import org.hibernate.annotations.NaturalIdCache; import org.hibernate.boot.MetadataSources; import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.CacheImplementor; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.metamodel.model.domain.NavigableRole; import org.hibernate.stat.NaturalIdCacheStatistics; import org.hibernate.stat.SecondLevelCacheStatistics; @@ -149,7 +148,7 @@ public class RegionNameTest extends BaseNonConfigCoreFunctionalTestCase { boolean foundRegion = false; for ( String name : cache.getSecondLevelCacheRegionNames() ) { - if ( EqualsHelper.areEqual( name, regionName ) ) { + if ( regionName.equals( name ) ) { foundRegion = true; break; } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java index c16c337600..1a4a031bf4 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/SinglePropertyMapper.java @@ -11,6 +11,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.List; import java.util.Map; +import java.util.Objects; import org.hibernate.HibernateException; import org.hibernate.collection.spi.PersistentCollection; @@ -22,7 +23,6 @@ import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.StringTools; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.property.access.spi.Setter; import org.hibernate.property.access.spi.SetterFieldImpl; @@ -171,6 +171,6 @@ public class SinglePropertyMapper extends AbstractPropertyMapper implements Simp } // todo (6.0) - Confirm if this is still necessary as everything should use a JavaTypeDescriptor. // This was maintained for legacy 5.2 behavior only. - return EqualsHelper.areEqual( newObj, oldObj ); + return Objects.deepEquals( newObj, oldObj ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index 55443b5264..174d5f2b36 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.hibernate.collection.spi.PersistentCollection; @@ -29,7 +30,6 @@ import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeD import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.ReflectionTools; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.property.access.spi.Setter; @@ -167,7 +167,7 @@ public abstract class AbstractCollectionMapper extends AbstractPropertyMapper if ( propertyData.isUsingModifiedFlag() ) { if ( isNotPersistentCollection( newObj ) || isNotPersistentCollection( oldObj ) ) { // Compare POJOs. - data.put( propertyData.getModifiedFlagPropertyName(), !EqualsHelper.areEqual( newObj, oldObj ) ); + data.put( propertyData.getModifiedFlagPropertyName(), !Objects.deepEquals( newObj, oldObj ) ); } else if ( isFromNullToEmptyOrFromEmptyToNull( (PersistentCollection) newObj, (Serializable) oldObj ) ) { data.put( propertyData.getModifiedFlagPropertyName(), true ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java index 6e989bafdf..7c4115db23 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/ToOneIdMapper.java @@ -8,6 +8,7 @@ package org.hibernate.envers.internal.entities.mapper.relation; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; @@ -17,7 +18,6 @@ import org.hibernate.envers.internal.entities.mapper.id.IdMapper; import org.hibernate.envers.internal.reader.AuditReaderImplementor; import org.hibernate.envers.internal.tools.EntityTools; import org.hibernate.envers.internal.tools.query.Parameters; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.persister.entity.EntityPersister; /** @@ -113,7 +113,7 @@ public class ToOneIdMapper extends AbstractToOneMapper { resolvedOldObjectId = EntityTools.getIdentifier( session, referencedEntityName, oldObj ); } - return !EqualsHelper.areEqual( resolvedNewObjectId, resolvedOldObjectId ); + return !Objects.deepEquals( resolvedNewObjectId, resolvedOldObjectId ); } @Override diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java index 152570c4bc..22438cd16b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/EntityTools.java @@ -6,11 +6,12 @@ */ package org.hibernate.envers.internal.tools; +import java.util.Objects; + import org.hibernate.Session; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.proxy.HibernateProxy; @@ -22,7 +23,7 @@ public abstract class EntityTools { final Object id1 = getIdentifier( session, entityName, obj1 ); final Object id2 = getIdentifier( session, entityName, obj2 ); - return EqualsHelper.areEqual( id1, id2 ); + return Objects.deepEquals( id1, id2 ); } public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java index e603e3b328..b1760cc0e9 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/Tools.java @@ -17,7 +17,6 @@ import java.util.Map; import java.util.Set; import org.hibernate.envers.tools.Pair; -import org.hibernate.internal.util.compare.EqualsHelper; /** * @author Adam Warski (adam at warski dot org) @@ -38,16 +37,6 @@ public abstract class Tools { return new LinkedHashMap<>(); } - /** - * @deprecated (since 5.2), use {@link EqualsHelper#areEqual(Object, Object)}. - */ - @Deprecated - public static boolean objectsEqual(Object obj1, Object obj2) { - // HHH-10734 - // Delegates to core's EqualsHelper to support array and non-array types - return EqualsHelper.areEqual( obj1, obj2 ); - } - public static List iteratorToList(Iterator iter) { final List ret = new ArrayList<>(); while ( iter.hasNext() ) {