You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chunk array constructors retain input arrays and can change existing patches #242
The Chunk array constructors say they save a copy of the affected lines, but the three-argument constructor stores Arrays.asList(lines). That list is backed by the caller's array. The two-argument array constructor delegates to it, so both retain the input.
Changing the source array after constructing a patch makes the patch fail its source check. Changing only the revised array silently changes what the patch writes. The List constructors already make a defensive copy.
If the source array is changed instead, applyTo throws PatchFailedException: CONTENT_DOES_NOT_MATCH_TARGET even when given the original source text.
Expected behavior
The patch should retain the line values supplied when the chunks were constructed. The example should return [new], consistently with the constructor Javadoc and the List overloads.
A one-line defensive copy fixes both array overloads. Three regression tests cover source-array mutation, the overload with change positions, and revised-array mutation. On unchanged source the tests produce two patch-application errors and one wrong-output assertion; all pass with the copy.
System
Linux, Temurin 17.0.21.
Current master 07a374624840a238e0c4e97dc94a30e0ac92ce28, version 4.19-SNAPSHOT.
Full mvn -B -ntp package passes across both modules: 173 tests, zero failures/errors, 3 existing skips, zero Checkstyle violations, and Javadocs built.
Activity