Title: Chunk array constructors retain input arrays and can change existing patches · Issue #242 · java-diff-utils/java-diff-utils · GitHub
Open Graph Title: Chunk array constructors retain input arrays and can change existing patches · Issue #242 · java-diff-utils/java-diff-utils
X Title: Chunk array constructors retain input arrays and can change existing patches · Issue #242 · java-diff-utils/java-diff-utils
Description: Describe the bug 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 deleg...
Open Graph Description: Describe the bug 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. ...
X Description: Describe the bug 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 arr...
Opengraph URL: https://github.com/java-diff-utils/java-diff-utils/issues/242
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Chunk array constructors retain input arrays and can change existing patches","articleBody":"**Describe the bug**\n\nThe `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.\n\nChanging 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.\n\n**To reproduce**\n\n```java\nString[] revised = {\"new\"};\nPatch\u003cString> patch = new Patch\u003c>();\npatch.addDelta(new ChangeDelta\u003c>(\n new Chunk\u003c>(0, new String[] {\"old\"}), new Chunk\u003c>(0, revised)));\nrevised[0] = \"changed revision\";\nSystem.out.println(patch.applyTo(Arrays.asList(\"old\")));\n```\n\nActual output: `[changed revision]`.\n\nIf the source array is changed instead, `applyTo` throws `PatchFailedException: CONTENT_DOES_NOT_MATCH_TARGET` even when given the original source text.\n\n**Expected behavior**\n\nThe 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.\n\nA 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.\n\n**System**\n\n- Linux, Temurin 17.0.21.\n- Current master `07a374624840a238e0c4e97dc94a30e0ac92ce28`, version `4.19-SNAPSHOT`.\n- Full `mvn -B -ntp package` passes across both modules: 173 tests, zero failures/errors, 3 existing skips, zero Checkstyle violations, and Javadocs built.","author":{"url":"https://github.com/parijat1222q","@type":"Person","name":"parijat1222q"},"datePublished":"2026-11-10T12:50:38Z","url":"https://github.com/java-diff-utils/java-diff-utils/issues/242"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e721bccf-1ca4-8427-8983-3960d29cfbd1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A514:14700E:34AC46F:42E851E:6B01DDC8 |
| html-safe-nonce | c405b6b140f252a88d354a83d3565d9df4e4e0771268beca3ef4d47e0a6941a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTE0OjE0NzAwRTozNEFDNDZGOjQyRTg1MUU6NkIwMUREQzgiLCJ2aXNpdG9yX2lkIjoiNTE3NTY3ODI3MjAxMjQxMDMxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4aa0cf73cc36c9a2368be93178d14a18cd49140fd44f365a46dbf71db9d042b7 |
| hovercard-subject-tag | issue:6307164049 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/java-diff-utils/java-diff-utils/242/issue_layout |
| twitter:image | https://opengraph.githubassets.com/35db16d4366283e63d4b71a80d4184f63c658552ab6655bb3ac6ad675a830082/java-diff-utils/java-diff-utils/issues/242 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/35db16d4366283e63d4b71a80d4184f63c658552ab6655bb3ac6ad675a830082/java-diff-utils/java-diff-utils/issues/242 |
| og:image:alt | Describe the bug 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. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | parijat1222q |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/java-diff-utils/java-diff-utils git https://github.com/java-diff-utils/java-diff-utils.git |
| octolytics-dimension-user_id | 40540835 |
| octolytics-dimension-user_login | java-diff-utils |
| octolytics-dimension-repository_id | 86663812 |
| octolytics-dimension-repository_nwo | java-diff-utils/java-diff-utils |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 86663812 |
| octolytics-dimension-repository_network_root_nwo | java-diff-utils/java-diff-utils |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width