From 3de7fb653ec3ad4cef2f8bd53a4aaf877255c413 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Mon, 23 Nov 2020 19:08:15 -0500 Subject: [PATCH] HHH-14346 Check declaredPluralAttributes for null before access --- .../model/domain/internal/AbstractManagedType.java | 2 +- .../org/hibernate/jpa/test/metadata/MetadataTest.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java index 7eccc87c3e..32a49056c4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java @@ -259,7 +259,7 @@ public abstract class AbstractManagedType @Override @SuppressWarnings({ "unchecked" }) public Set> getPluralAttributes() { - HashSet attributes = declaredAttributes == null ? new HashSet>() : new HashSet>( declaredPluralAttributes.values() ); + HashSet attributes = declaredPluralAttributes == null ? new HashSet>() : new HashSet>( declaredPluralAttributes.values() ); if ( getSuperType() != null ) { attributes.addAll( getSuperType().getPluralAttributes() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index a2831032c1..f09117d8a5 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -31,6 +31,7 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.metamodel.internal.MetamodelImpl; +import org.hibernate.testing.TestForIssue; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -268,6 +269,14 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase { assertTrue( flowers instanceof ListAttribute ); } + @Test + @TestForIssue( jiraKey = "HHH-14346" ) + public void testEmptyPluralAttributeSet() throws Exception { + final EntityType entityType = entityManagerFactory().getMetamodel().entity( Feline.class ); + final Set> attributes = entityType.getPluralAttributes(); + assertEquals( 0, attributes.size() ); + } + @Test public void testElementCollection() throws Exception { final EntityType entityType = entityManagerFactory().getMetamodel().entity( House.class );