Bug in InheritanceInfoProvider.CheckIfIsSubTypeOf

Posts   
 
    
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 03-Jul-2019 12:23:10   

Hi.

In version 5.5.3 the use of _entityToPathToRoot[typeToCheck] in InheritanceInfoProvider.CheckIfIsSubTypeOf causes a KeyNotFoundException:

public bool CheckIfIsSubTypeOf(string typeToCheck, string superType)
        {
            if (!_entityToEntityInfo.ContainsKey(superType))
            {
                return false;
            }
            return _entityToPathToRoot[typeToCheck].Contains(superType);
        }

Should it be like this?

public bool CheckIfIsSubTypeOf(string typeToCheck, string superType) {
            if (!_entityToEntityInfo.ContainsKey(superType)) {
                return false;
            }
            return _entityToPathToRoot.TryGetValue(typeToCheck, out var superTypes) && superTypes.Contains(superType);
        }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 04-Jul-2019 09:48:09   

The code is indeed not that solid, as it assumes currently that typeToCheck is an entity type (so the entry is always there). So I assume you ran into this when you passed a type that's not an entity type? (which is a legitimate call, it indeed shouldn't crash on that)

We'll add a change so it's more reliably simple_smile

Frans Bouma | Lead developer LLBLGen Pro
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 04-Jul-2019 10:15:49   

Thanks simple_smile

We are using the IEntity2 CheckIfIsSubTypeOf which takes an integer.

I added two extensions methods to get around the issue. I am calling the top one when I get the exception.

public static bool CheckIfIsSubTypeOf(this IEntity2 entity, IEntityCollection2 entityCollection) {
            return entity.CheckIfIsSubTypeOf(entityCollection.EntityFactoryToUse.ForEntityName);
        }

        public static bool CheckIfIsSubTypeOf(this IEntity2 entity, string entityName) {
            try {
                return entity.CheckIfIsSubTypeOf((int)Enum.Parse(typeof(EntityType), entityName));
            } catch (KeyNotFoundException) {
                return false;
            }
        }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 05-Jul-2019 10:46:55   

The fix for this is now available in the 5.4.7 and 5.5.4 hotfix builds.

Frans Bouma | Lead developer LLBLGen Pro
hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 05-Jul-2019 14:46:01   

Thank you, but the new implementation gives null pointer exception. You are using default(TValue) which give null for List<string>. So it makes sense.

Also we should be passing a valid entity name here because we are going via the EntityType enum.

hotchill avatar
hotchill
User
Posts: 180
Joined: 22-Jan-2007
# Posted on: 05-Jul-2019 15:01:27   

We have debugged this. The dictionary only contains those entities that are a part of an inheritance hierarchy.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 06-Jul-2019 10:39:05   

Ok, yes it's stupid.. flushed Fixing.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 06-Jul-2019 10:54:57   

Fixed in new hotfix build, now available. Sorry for this inconvenience.

Frans Bouma | Lead developer LLBLGen Pro