Skip to content

fix(compare): avoid ordering differences for identical arrays - #113

Merged
puneetkhanduri merged 1 commit into
opendiffy:masterfrom
prado-rafael:fix/opendiffy-identical-array-comparison
Nov 7, 2026
Merged

puneetkhanduri merged 1 commit into
opendiffy:masterfrom
prado-rafael:fix/opendiffy-identical-array-comparison

Conversation

@prado-rafael

Copy link
Copy Markdown
Contributor

Summary

Return NoDifference for identical lists before dispatching to diffSeq. Equal arrays should not be classified as ordering regressions or increment the different-request counter.

This is a one-line, list-specific equality guard. It preserves object/map traversal and field-level NoDifference metadata, rather than introducing a broad object-equality short circuit or suppressing all ordering differences.

Problem and minimal reproduction

Comparing two identical responses currently produces:

// Primary and candidate
{"content": []}

// Current flattened comparison result
{
  "value.content.OrderingDifference": {
    "type": "OrderingDifference",
    "left": [],
    "right": []
  }
}

Non-empty equal arrays have the same problem: ["a", "b"] versus ["a", "b"] yields an OrderingDifference with [0, 1] on both sides. diffSeq emits that type whenever the arrays have matching elements, without first checking whether the lists are already equal. The request counter excludes only NoDifference, so these comparisons become false-positive different requests.

An earlier report describes this exact empty/singleton-array behavior: #95 (comment).

Expected behavior

Primary Candidate Expected classification
[] [] NoDifference
["a", "b"] ["a", "b"] NoDifference
[1, 1, 2] [1, 1, 2] NoDifference
[1, 2] [2, 1] OrderingDifference
[1, 2] [1, 3] Value difference
[1, 2] [1, 2, 3] Size difference

TDD and validation

Tests were added before modifying Difference.java:

  • Red: 20 focused tests executed, 12 failed, 8 passed, 0 errors. Failures cover equal arrays and the false-positive request counter.
  • Green: after the one-line guard, the same 20 tests passed.
  • Complete JVM suite: 25 tests passed, 0 failures, 0 errors.
  • git diff --check passed.

Coverage includes empty, singleton, populated, repeated-element, nested and mixed JSON arrays, native arrays, retained field-level metadata, actual ordering/value/size differences, and the real in-memory request counter. Genuine ordering differences still increment the counter; identical responses do not.

Commands (JDK 21):

mvn -B -Dskip.installnodeyarn -Dskip.yarn \
  -Dtest=DifferenceTest,InMemoryDifferenceCounterTest test

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

Frontend tasks were skipped for this backend-only change. My local Maven settings add unrelated repositories, so the commands were executed with temporary -s / -gs settings pointing to Maven Central. No project build configuration or dependencies were changed.

Scope

The equivalent Scala fix and regression tests are proposed separately in the downstream fork: syngenta#6. This PR targets the current Java implementation and contains no deployment changes, UI changes, counter workarounds, or production data.

Agent on behalf of @prado-rafael

@puneetkhanduri
puneetkhanduri merged commit 4cc1dfd into opendiffy:master Nov 7, 2026
5 of 7 checks passed
puneetkhanduri added a commit that referenced this pull request Nov 7, 2026
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: Puneet Khanduri <puneet.khanduri@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

4 participants