New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect change reported for maps with array-typed values #546

Closed
neal-erickson opened this Issue Jun 12, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@neal-erickson

neal-erickson commented Jun 12, 2017

Was trying to find an existing issue for this, but couldn't - might not have done a good job though! I'm working with your otherwise excellent library for comparing some kafka serialization classes I'm writing and found an odd behavior. One of the objects I'm comparing has a field of type Map<String, UUID[]> and when I serialize/deserialize it I find that Javers reports a MapChange change for that value, despite the UUID within the array being identical. This simple JUnit test reproduces the issue:

@Test
public void checkMapEqualitySane() {

    UUID uuid = UUID.randomUUID();
    UUID[] array1 = new UUID[1];
    UUID[] array2 = new UUID[1];
    array1[0] = uuid;
    array2[0] = uuid;
    String key = "1";

    Map<String, UUID[]> map1 = new HashMap<>();
    map1.put(key, array1);
    Map<String, UUID[]> map2 = new HashMap<>();
    map2.put(key, array2);

    Diff diff = JaversBuilder.javers().build().compare(map1, map2);
    assertFalse(diff.hasChanges());
}

Let me know if I'm missing something obvious here, but I couldn't find anything. Thanks for your time.

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jun 19, 2017

Hi @neal-erickson , thanks for reporting. Looks like there is a problem with array.equals() in Java.

array1.equals(array2) is the same as array1 == array2 so false in your case
see https://stackoverflow.com/questions/8777257/equals-vs-arrays-equals-in-java

Looks like we should use Arrays.equals instead. We can do it, but still, since you have arrays nested in Maps, you will get only basic diff (Javers treats arrays as Values in this case)

@bartoszwalacik bartoszwalacik added the bug label Jun 19, 2017

bartoszwalacik added a commit that referenced this issue Jun 25, 2017

bartoszwalacik added a commit that referenced this issue Jun 25, 2017

@bartoszwalacik

This comment has been minimized.

Member

bartoszwalacik commented Jun 25, 2017

fixed in 3.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment