This project is read-only.
1
Vote

Cache hash key creates duplicates

description

Just wanted to give you a heads up that I found an issue in the cache logic for caching adapters. The logic of creating a cache key is:
private static FastInvokeHandler GetAdapter(Type sourceType, Type destinationType, bool hasDestination = false)
    {
        int hashCode = sourceType.GetHashCode() + destinationType.GetHashCode();
The core flaw here is that if you have a two way mapping defined TypeA-->TypeB as well as the inverse TypeB --> TypeA, the integer hash code is the same for both mappings since you are adding together the hash of the source and destination.

My quick fix is to divide the source hash code / 2 to create unique combinations in both situations.
int hashCode = (sourceType.GetHashCode()/2) + destinationType.GetHashCode();

comments