Skip to content

Invalid Diff because of duplicate hashes of global ids #1370

Description

@MaxKlotz

Comparing two collections by using <T> Diff compareCollections(Collection<T> oldVersion, Collection<T> currentVersion, Class<T> itemClass);.
The elements in the collection are the same type.
The elements in the collection are entities.

Expectation:
All objects, identified by global id, that are present in the currentVersion, but missing in oldVersion, are present in the NewObject changes.

Reality:
Some entites, that are new, to not produce a NewObject change.

...

Steps To Reproduce

  1. Create two collections.
  2. Add elements to the collection with a different ID, that produces the same hash value. e.g. "FB" and "Ea"
  3. Compare the two lists by using <T> Diff compareCollections(Collection<T> oldVersion, Collection<T> currentVersion, Class<T> itemClass);

Javers' Version
7.3.8

Additional context
I identified the root cause of this:
In GraphPair the graphs are built and the comparison in difference is done by using a hasher.
The wrong result happens because 2 different global IDs produce the same hash value.
So the oldVersion contains a different element with the same hash, thus it is not recoignized as a new object in the currentVersion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions