Skip to content

Copy input arrays when constructing chunks - #243

Open
parijat1222q wants to merge 1 commit into
java-diff-utils:masterfrom
parijat1222q:fix/chunk-array-copy
Open

parijat1222q wants to merge 1 commit into
java-diff-utils:masterfrom
parijat1222q:fix/chunk-array-copy

Conversation

@parijat1222q

Copy link
Copy Markdown

Fixes #242.

The array constructors promise a copy, but Arrays.asList(lines) keeps the caller's array. Mutating a source array can make a previously constructed patch fail verification; mutating a revised array silently changes its output.

Copy the array-backed list into an ArrayList, matching the existing List overload. The two-argument array overload delegates to this constructor, so both paths are covered by the one-line fix. No change to the separate mutable getLines/setLines API.

Three regressions exercise patch application after source/revised array changes and the overload with change positions. All three fail on the unchanged implementation: two source-verification errors and one wrong-output assertion.

Validation on Linux, Temurin 17.0.21:

  • mvn -B -ntp package passes across both modules.
  • 173 tests, zero failures/errors, 3 existing skipped tests.
  • Zero Checkstyle violations; Javadocs built.
  • The formatter's existing JDK21 incompatibility was avoided by using JDK17, which is in the repository's CI matrix. No build or test checks were disabled.

Keep saved patch lines independent of the caller's array, matching the
List constructors and the documented copy semantics. Add regressions
for source and revised array changes through both constructor paths.

Fixes java-diff-utils#242

This branch has not been deployed

No deployments
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.

Chunk array constructors retain input arrays and can change existing patches

1 participant