Skip to content

fix(compare): detect reordered arrays of objects - #114

Merged
puneetkhanduri merged 1 commit into
opendiffy:masterfrom
proofaml:fix/fieldmap-equality
Nov 7, 2026
Merged

puneetkhanduri merged 1 commit into
opendiffy:masterfrom
proofaml:fix/fieldmap-equality

Conversation

@proofaml

@proofaml proofaml commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #113, now merged. This branch has been rebased onto master.

FieldMap had no equals/hashCode, so diffSeq's removeAll never matched JSON objects. Reordered arrays of objects therefore fell through to an index-by-index comparison and were reported as field-level value differences instead of an ordering difference.

[{"a":1},{"a":2}]  vs  [{"a":2},{"a":1}]
before: value.a.PrimitiveDifference
after:  value.OrderingDifference

Changes

  • FieldMap gets value equality based on its underlying map. Key order does not affect equality.
  • Equal lists of objects are still walked element by element, so their field-level NoDifference metadata is kept. Equal lists of primitives still return a single NoDifference, as in fix(compare): avoid ordering differences for identical arrays #113.

Why this builds on #113: without its equal-list guard, FieldMap equality would make identical object arrays hit the same false OrderingDifference that #113 fixes for primitive arrays.

Tests

New tests cover reordered flat and nested object arrays, identical object arrays keeping field-level metadata, changed object arrays still reporting field differences, and FieldMap equality and hash code. Three of them fail without the fix.

Full JVM suite on JDK 21: 31 tests, 0 failures.

mvn -B -Dskip.installnodeyarn -Dskip.yarn -DargLine=-Djdk.http.maxHeaderSize=33554432 test

Known limitation, not changed here

diffSeq uses removeAll, which ignores element counts. [a, a, b] vs [a, b, b] is still reported as an ordering difference rather than a value difference. This already applied to primitive arrays and is left for a separate change.

🤖 Generated with Claude Code

FieldMap had no equals/hashCode, so diffSeq's removeAll never matched
JSON objects. Reordered object arrays fell through to an index-by-index
comparison and were reported as field-level PrimitiveDifferences instead
of an OrderingDifference.

Give FieldMap value equality. Identical arrays of objects are still
walked element by element so their field-level NoDifference metadata is
retained rather than collapsing into a single array-level entry.

Builds on #113, which this depends on: without its equal-list guard,
FieldMap equality would make identical object arrays report a false
OrderingDifference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@puneetkhanduri
puneetkhanduri merged commit fed9b44 into opendiffy:master Nov 7, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants