Skip to content
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

Comparison of Set of Set non-deterministic #1157

Closed
samba2 opened this issue Nov 2, 2021 · 7 comments
Closed

Comparison of Set of Set non-deterministic #1157

samba2 opened this issue Nov 2, 2021 · 7 comments

Comments

@samba2
Copy link

samba2 commented Nov 2, 2021

I have a data structure which contains a set of set. When comparing with javers I sometimes get a diff, sometimes not. The test data is static so I would expect an identical output.

Steps To Reproduce

When I run this class containing the two identical objects a1 and a2:

import lombok.Builder;
import lombok.Data;
import org.javers.core.Javers;
import org.javers.core.JaversBuilder;

import java.util.Set;

public class MyTest {

    @Data
    @Builder
    public static class A {
        private Set<B> bs;
    }

    @Data
    @Builder
    public static class B {
        private Set<C> cs;
    }

    @Data
    @Builder
    public static class C {
        private String foo;
    }

    public static void main(String[] args) {
        Javers javers = JaversBuilder.javers().build();

        A a1 = A.builder().bs(Set.of(
                        B.builder()
                            .cs(
                                Set.of(
                                    C.builder().foo("a").build(),
                                    C.builder().foo("b").build()
                                        )).build())).build();

        A a2 = A.builder().bs(Set.of(
                B.builder()
                        .cs(
                                Set.of(
                                        C.builder().foo("a").build(),
                                        C.builder().foo("b").build()
                                )).build())).build();


        for (int i = 0; i < 10; i++) {
            var diff = javers.compare(a1, a2);
            if (diff.hasChanges()) {
                System.out.printf("\n===== Diff at round %d ======\n", i);
                System.out.println(diff);
            }
        }
    }
}

... I receive the following output:

20:51:47.647 [main] DEBUG org.javers.core.JaversBuilder - starting up JaVers ...
20:51:47.724 [main] INFO org.javers.core.JaversBuilder - mappingStyle: FIELD
20:51:47.732 [main] INFO org.javers.core.JaversBuilder - loading JodaAddOns ...
20:51:47.786 [main] INFO org.javers.core.JaversBuilder - loading GuavaAddOns ...
20:51:47.841 [main] DEBUG org.javers.TypeMapper - javersType of 'LocalDateTime' mapped explicitly to ValueType
20:51:47.841 [main] DEBUG org.javers.TypeMapper - javersType of 'LocalDate' mapped explicitly to ValueType
20:51:47.842 [main] INFO org.javers.core.JaversBuilder - using fake InMemoryRepository, register actual Repository implementation via JaversBuilder.registerJaversRepository()
20:51:47.870 [main] INFO org.javers.core.JaversBuilder - JaVers instance started in 225 ms
20:51:47.890 [main] DEBUG org.javers.TypeMapper - javersType for 'class MyTest$A' defaulted to ValueObjectType
20:51:47.903 [main] DEBUG org.javers.TypeMapper - javersType for 'java.util.Set<MyTest$B>' spawned as SetType from prototype SetType{ baseType: 'interface java.util.Set' }
20:51:47.905 [main] DEBUG org.javers.TypeMapper - javersType for 'class MyTest$B' defaulted to ValueObjectType
20:51:47.907 [main] DEBUG org.javers.TypeMapper - javersType for 'java.util.Set<MyTest$C>' spawned as SetType from prototype SetType{ baseType: 'interface java.util.Set' }
20:51:47.908 [main] DEBUG org.javers.TypeMapper - javersType for 'class MyTest$C' defaulted to ValueObjectType
20:51:47.909 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.938 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.949 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.951 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3

===== Diff at round 1 ======
Diff:
* changes on MyTest$A/ :
  - 'bs' collection changes :
     . 'MyTest$A/#bs/9f83e3c27e7b610b0a0317a0f008f195' removed
     · 'MyTest$A/#bs/f80bbd079e4ee10592dc0f6f850bacb7' added
  - 'bs/9f83e3c27e7b610b0a0317a0f008f195.cs' collection changes :
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' removed
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' removed
  - 'bs/f80bbd079e4ee10592dc0f6f850bacb7.cs' collection changes :
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' added
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' added

20:51:47.971 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.972 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3

===== Diff at round 2 ======
Diff:
* changes on MyTest$A/ :
  - 'bs' collection changes :
     . 'MyTest$A/#bs/9f83e3c27e7b610b0a0317a0f008f195' removed
     · 'MyTest$A/#bs/f80bbd079e4ee10592dc0f6f850bacb7' added
  - 'bs/9f83e3c27e7b610b0a0317a0f008f195.cs' collection changes :
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' removed
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' removed
  - 'bs/f80bbd079e4ee10592dc0f6f850bacb7.cs' collection changes :
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' added
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' added

20:51:47.978 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.980 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.982 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.983 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.985 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.987 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.989 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.991 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3

===== Diff at round 6 ======
Diff:
* changes on MyTest$A/ :
  - 'bs' collection changes :
     . 'MyTest$A/#bs/9f83e3c27e7b610b0a0317a0f008f195' removed
     · 'MyTest$A/#bs/f80bbd079e4ee10592dc0f6f850bacb7' added
  - 'bs/9f83e3c27e7b610b0a0317a0f008f195.cs' collection changes :
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' removed
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' removed
  - 'bs/f80bbd079e4ee10592dc0f6f850bacb7.cs' collection changes :
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' added
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' added

20:51:47.994 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.996 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.997 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:47.998 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:48.000 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3
20:51:48.001 [main] DEBUG org.javers.core.graph.ObjectGraphBuilder - live graph assembled, object nodes: 4, entities: 0, valueObjects: 3

===== Diff at round 9 ======
Diff:
* changes on MyTest$A/ :
  - 'bs' collection changes :
     . 'MyTest$A/#bs/9f83e3c27e7b610b0a0317a0f008f195' removed
     · 'MyTest$A/#bs/f80bbd079e4ee10592dc0f6f850bacb7' added
  - 'bs/9f83e3c27e7b610b0a0317a0f008f195.cs' collection changes :
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' removed
     . 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' removed
  - 'bs/f80bbd079e4ee10592dc0f6f850bacb7.cs' collection changes :
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/74a563c16582541b5f7d011fe538602a' added
     · 'MyTest$A/#bs/{hashPlaceholder}/cs/7f2b9fa7d40fb28ae704fb57f5db54ee' added


Process finished with exit code 0

Interestingly enough the diff appears (at least on my machine) always on the same rounds.
When the inner set (Set of C) only contains one entry, the diff works as expected - there is no difference ;-)

What do I miss?

Javers' Version
6.42

Additional context

  • I am a JaVers newbie
  • I have tried the three different list comparison algorithms without a change of the output above.
@bartoszwalacik
Copy link
Member

hi, please push your code as a failing test case, see https://github.com/javers/javers/blob/master/CONTRIBUTING.md#guidelines-for-bug-reporting

@samba2
Copy link
Author

samba2 commented Nov 3, 2021

Hi, I've tried to fumble together a failing test case: #1158

Please feel free to improve my copy + paste groovy code ;-)

@bartoszwalacik
Copy link
Member

@samba2 thanks for the valid bug report, the fix will be released tomorrow

@samba2
Copy link
Author

samba2 commented Dec 4, 2021

@bartoszwalacik thank you for fixing!

@bartoszwalacik
Copy link
Member

fixed in 6.5.3

@samba2
Copy link
Author

samba2 commented Dec 6, 2021

just want to confirm that the fix also works in my actual use case ;-) many tnx again!

@bartoszwalacik
Copy link
Member

it should, just try the new version :)

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

No branches or pull requests

2 participants