HHH-14346 Check declaredPluralAttributes for null before access

This commit is contained in:
Michael Edgar 2020-11-23 19:08:15 -05:00 committed by Sanne Grinovero
parent 8ded205b5f
commit 3de7fb653e
2 changed files with 10 additions and 1 deletions

View File

@ -259,7 +259,7 @@ public abstract class AbstractManagedType<J>
@Override @Override
@SuppressWarnings({ "unchecked" }) @SuppressWarnings({ "unchecked" })
public Set<PluralAttribute<? super J, ?, ?>> getPluralAttributes() { public Set<PluralAttribute<? super J, ?, ?>> getPluralAttributes() {
HashSet attributes = declaredAttributes == null ? new HashSet<PluralAttribute<? super J, ?, ?>>() : new HashSet<PluralAttribute<? super J, ?, ?>>( declaredPluralAttributes.values() ); HashSet attributes = declaredPluralAttributes == null ? new HashSet<PluralAttribute<? super J, ?, ?>>() : new HashSet<PluralAttribute<? super J, ?, ?>>( declaredPluralAttributes.values() );
if ( getSuperType() != null ) { if ( getSuperType() != null ) {
attributes.addAll( getSuperType().getPluralAttributes() ); attributes.addAll( getSuperType().getPluralAttributes() );
} }

View File

@ -31,6 +31,7 @@ import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting;
import org.hibernate.metamodel.internal.MetamodelImpl; import org.hibernate.metamodel.internal.MetamodelImpl;
import org.hibernate.testing.TestForIssue;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -268,6 +269,14 @@ public class MetadataTest extends BaseEntityManagerFunctionalTestCase {
assertTrue( flowers instanceof ListAttribute ); assertTrue( flowers instanceof ListAttribute );
} }
@Test
@TestForIssue( jiraKey = "HHH-14346" )
public void testEmptyPluralAttributeSet() throws Exception {
final EntityType<Feline> entityType = entityManagerFactory().getMetamodel().entity( Feline.class );
final Set<PluralAttribute<? super Feline, ?, ?>> attributes = entityType.getPluralAttributes();
assertEquals( 0, attributes.size() );
}
@Test @Test
public void testElementCollection() throws Exception { public void testElementCollection() throws Exception {
final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class ); final EntityType<House> entityType = entityManagerFactory().getMetamodel().entity( House.class );