Skip to content

java.lang.IllegalArgumentException: argument should not be null when comparing objects with nested hashes #1269

Closed

Description

@noahhaon

First, thank you for a fantastic project!

I have two objects that have member Maps that when one Map has a key/value pair with a null value, I get an exception java.lang.IllegalArgumentException: argument should not be null when I call javers.compare() on the two objects. I think this case should be covered by Javers, but I wanted to report it in case others hit it.

Steps To Reproduce

Apologies for inlining the test case, but thankfully it is quite simple

    public void testJaversNullHashValue() {
        class TestChild {
            String value;

            public TestChild(String value) {
                this.value = value;
            }
        }

        class TestParent {
            Map<String, TestChild> childMap = new HashMap<>();

            public Map<String, TestChild> getChildMap() {
                return childMap;
            }
        }

        Javers javers = JaversBuilder.javers().build();

        TestParent tp1 = new TestParent();
        TestParent tp2 = new TestParent();

        tp1.getChildMap().put("test", null);
        tp2.getChildMap().put("test", new TestChild("value"));

        javers.compare(tp1, tp2);
    }

Javers' Version
6.5.3

Additional context

Full stack trace:

java.lang.IllegalArgumentException: argument should not be null

	at org.javers.common.validation.Validate.argumentsAreNotNull(Validate.java:33)
	at org.javers.core.metamodel.object.GlobalIdFactory.createId(GlobalIdFactory.java:40)
	at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:37)
	at org.javers.core.graph.EdgeBuilder.lambda$createMultiEdge$0(EdgeBuilder.java:63)
	at org.javers.core.metamodel.type.MapType.mapEntrySet(MapType.java:76)
	at org.javers.core.metamodel.type.MapType.map(MapType.java:34)
	at org.javers.core.graph.EdgeBuilder.createMultiEdge(EdgeBuilder.java:70)
	at org.javers.core.graph.ObjectGraphBuilder.buildMultiEdges(ObjectGraphBuilder.java:116)
	at org.javers.core.graph.ObjectGraphBuilder.buildEdges(ObjectGraphBuilder.java:96)
	at org.javers.core.graph.ObjectGraphBuilder.buildGraphFromCdo(ObjectGraphBuilder.java:62)
	at org.javers.core.graph.ObjectGraphBuilder.buildGraph(ObjectGraphBuilder.java:51)
	at org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:38)
	at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:102)
	at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:55)
	at org.javers.core.JaversCore.compare(JaversCore.java:176)

Activity

  1. bartoszwalacik commented on Mar 5, 2023

    @bartoszwalacik
    Member

    Thanks for reporting, this is quite easy to fix, entries with null values should be ignored while comparing. Feel free to contribute a PR with the fix

  2. rh-id commented on Jun 3, 2023

    @rh-id
    Contributor

    Hi @bartoszwalacik I helped create PR to fix this issue, please help review it.

  3. added 2 commits that reference this issue on Jul 27, 2023
  4. bartoszwalacik commented on Jul 28, 2023

    @bartoszwalacik
    Member

    this fix was released in 7.3.1, thanks @noahhaon

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

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