Skip to content

Commit

Permalink
HHH-12383 - Type check existing type to avoid class cast exceptions r…
Browse files Browse the repository at this point in the history
…elated to type incompatible same named attributes being used in subtypes
  • Loading branch information
beikov authored and dreab8 committed Mar 21, 2018
1 parent c8217d9 commit 5d9675c
Showing 1 changed file with 19 additions and 12 deletions.
Expand Up @@ -127,6 +127,18 @@ private void logDuplicateRegistration(String path, Type existingType, Type type)
}
}

private void logIncompatibleRegistration(String path, Type existingType, Type type) {
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
"Skipped adding same named type incompatible property to base type [{0}] for property [{1}], existing type = [{2}], incoming type = [{3}]",
getEntityName(),
path,
existingType,
type
);
}
}

/**
* Only kept around for compatibility reasons since this seems to be API.
*
Expand Down Expand Up @@ -176,11 +188,11 @@ protected void addPropertyPath(
Type newType = null;
MetadataImplementor metadata = (MetadataImplementor) factory;

if ( type instanceof AnyType ) {
if ( type instanceof AnyType && existingType instanceof AnyType ) {
// TODO: not sure how to handle any types. For now we just return and let the first type dictate what type the property has...
return;
}
else if ( type instanceof CollectionType ) {
else if ( type instanceof CollectionType && existingType instanceof CollectionType ) {
Collection thisCollection = metadata.getCollectionBinding( ( (CollectionType) existingType ).getRole() );
Collection otherCollection = metadata.getCollectionBinding( ( (CollectionType) type ).getRole() );

Expand All @@ -195,17 +207,9 @@ else if ( type instanceof CollectionType ) {

// When we discover incompatible types, we use "null" as property type to signal that the property is not resolvable on the parent type
newType = null;
if ( LOG.isTraceEnabled() ) {
LOG.tracev(
"Skipped adding same named type incompatible property to base type [{0}] for property [{1}], existing type = [{2}], incoming type = [{3}]",
getEntityName(),
path,
existingType,
type
);
}
logIncompatibleRegistration(path, existingType, type);
}
else if ( type instanceof EntityType ) {
else if ( type instanceof EntityType && existingType instanceof EntityType ) {
EntityType entityType1 = (EntityType) existingType;
EntityType entityType2 = (EntityType) type;

Expand All @@ -220,6 +224,9 @@ else if ( type instanceof EntityType ) {

newType = getCommonType( metadata, entityType1, entityType2 );
}
else {
logIncompatibleRegistration(path, existingType, type);
}

typesByPropertyPath.put( path, newType );
// Set everything to empty to signal action has to be taken!
Expand Down

0 comments on commit 5d9675c

Please sign in to comment.