René's URL Explorer Experiment


Title: Number single-delta hunks correctly when the original file name is null by simpleqt · Pull Request #241 · java-diff-utils/java-diff-utils · GitHub

Open Graph Title: Number single-delta hunks correctly when the original file name is null by simpleqt · Pull Request #241 · java-diff-utils/java-diff-utils

X Title: Number single-delta hunks correctly when the original file name is null by simpleqt · Pull Request #241 · java-diff-utils/java-diff-utils

Description: Problem UnifiedDiffUtils.generateUnifiedDiff treats any single-delta patch with a null original file name as a newly created file. The new-file flag reaches processDeltas, which then hardcodes the hunk start of the original side to 0 regardless of where the delta is. For a patch that replaces or deletes lines this writes a header naming a line that does not exist. Reproduction (public API only, no context lines): List original = Arrays.asList("a", "b", "c"); List revised = Arrays.asList("a", "x", "c"); Patch patch = DiffUtils.diff(original, revised); UnifiedDiffUtils.generateUnifiedDiff(null, "revised", original, patch, 0) .forEach(System.out::println); Actual output: --- /dev/null +++ revised @@ -0,1 +2,1 @@ -b +x diff -U0 and git diff -U0 write @@ -2,1 +2,1 @@ for the same change: $ git diff --no-index --no-color -U0 -- a.txt b.txt --- a/a.txt +++ b/b.txt @@ -2 +2 @@ -b +x (difflib.unified_diff(..., n=0) produces @@ -2 +2 @@ as well.) The damage is not only cosmetic. parseUnifiedDiff applies the library's own "an empty range names the line before it" rule to the 0 and produces a ChangeDelta at position 0 instead of position 1, so the generated diff no longer applies to the file it was generated from: replacing or deleting a line → PatchFailedException: could not apply patch due to CONTENT_DOES_NOT_MATCH_TARGET pure insertion → applies silently at the wrong place, e.g. [a, b, c] -> [a, b, c, x] generated with a null name applies as [x, a, b, c] Appending with one line of context, or using two or more deltas, numbers correctly — the bug is specific to a lone delta whose source side is not empty. Fix java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java:196 The new-file handling is now restricted to patches whose source chunk is empty, which is what actually distinguishes "created this file" from "renamed/no original name given": patchDeltas.size() == 1 && originalFileName == null && delta.getSource().size() == 0 A genuine new file (empty original, null name) still emits @@ -0,0 +1,N @@, unchanged. Patches with two or more deltas are untouched. Tests GenerateUnifiedDiffTest.testSingleDeltaWithNullOriginalNameKeepsOriginalLineNumbers asserts the header, the body and — importantly — that the generated diff still parses back and applies to the original. Run with the unmodified baseline (git stash of the one-line source change, test kept): [ERROR] GenerateUnifiedDiffTest.testSingleDeltaWithNullOriginalNameKeepsOriginalLineNumbers:168 expected: <@@ -2,1 +2,1 @@> but was: <@@ -0,1 +2,1 @@> [ERROR] Tests run: 14, Failures: 1, Errors: 0 With the fix (the whole reactor, mvn -B package on JDK 17): [INFO] Tests run: 169, Failures: 0, Errors: 0, Skipped: 3 (core module) [INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 (java-diff-utils-jgit) [INFO] BUILD SUCCESS The 3 skipped tests are skipped on master as well. Spotless (palantirJavaFormat, bound to validate) is applied to the changed files. Note UnifiedDiffWriter.processDeltas carries the same patchDeltas.size() == 1 && file.getFromFile() == null condition, so a UnifiedDiffFile whose fromFile is null has the same numbering problem. I left that out of this change to keep it to one subject — happy to follow up separately if you want both sides fixed.

Open Graph Description: Problem UnifiedDiffUtils.generateUnifiedDiff treats any single-delta patch with a null original file name as a newly created file. The new-file flag reaches processDeltas, which then hardcodes the ...

X Description: Problem UnifiedDiffUtils.generateUnifiedDiff treats any single-delta patch with a null original file name as a newly created file. The new-file flag reaches processDeltas, which then hardcodes the ...

Opengraph URL: https://github.com/java-diff-utils/java-diff-utils/pull/241

X: @github

direct link

Domain: github-redirect.dependabot.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:3378bd0c-d0e9-756a-3bb3-836d92dc5c9a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8E8A:A71F9:2BF06D1:37A38E5:6B01E6B2
html-safe-nonceafcd378cf17613c9a19a5c17d84a8bb82c64f914d094e2fda3beb8544cf15e77
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RThBOkE3MUY5OjJCRjA2RDE6MzdBMzhFNTo2QjAxRTZCMiIsInZpc2l0b3JfaWQiOiI4NjY4MjEyMjg4MzIwMzAwNzIyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd6634166b1571d33a386bb570cf7121e0e98facfb6a213e085c9196916c12619
hovercard-subject-tagpull_request:5158009020
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/java-diff-utils/java-diff-utils/pull/241/files
twitter:imagehttps://avatars.githubusercontent.com/u/89645338?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/89645338?s=400&v=4
og:image:altProblem UnifiedDiffUtils.generateUnifiedDiff treats any single-delta patch with a null original file name as a newly created file. The new-file flag reaches processDeltas, which then hardcodes the ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/java-diff-utils/java-diff-utils git https://github.com/java-diff-utils/java-diff-utils.git
octolytics-dimension-user_id40540835
octolytics-dimension-user_loginjava-diff-utils
octolytics-dimension-repository_id86663812
octolytics-dimension-repository_nwojava-diff-utils/java-diff-utils
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id86663812
octolytics-dimension-repository_network_root_nwojava-diff-utils/java-diff-utils
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#start-of-content
https://github-redirect.dependabot.com/
Sign inhttps://github-redirect.dependabot.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjava-diff-utils%2Fjava-diff-utils%2Fpull%2F241%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github-redirect.dependabot.com/login?return_to=https%3A%2F%2Fgithub.com%2Fjava-diff-utils%2Fjava-diff-utils%2Fpull%2F241%2Ffiles
Sign uphttps://github-redirect.dependabot.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=java-diff-utils%2Fjava-diff-utils
Reloadhttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Reloadhttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Reloadhttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
java-diff-utilshttps://github-redirect.dependabot.com/java-diff-utils
java-diff-utilshttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils
Codehttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils
Issues2 (2)https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/issues
Pull requests2 (2)https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pulls
Discussionshttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/discussions
Actionshttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/actions
Projectshttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/projects
Wikihttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/wiki
Security and qualityhttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/security
Insightshttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/insights
Sign up for GitHub https://github-redirect.dependabot.com/signup?return_to=%2Fjava-diff-utils%2Fjava-diff-utils%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github-redirect.dependabot.com/login?return_to=%2Fjava-diff-utils%2Fjava-diff-utils%2Fissues%2Fnew%2Fchoose
simpleqthttps://github-redirect.dependabot.com/simpleqt
java-diff-utils:masterhttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/tree/master
simpleqt:fix/null-original-name-hunk-rangehttps://github-redirect.dependabot.com/simpleqt/java-diff-utils/tree/fix/null-original-name-hunk-range
Conversation 1 https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241
Commits 1 https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/commits
Checks 1 https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/checks
Files changed https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Please reload this pagehttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Number single-delta hunks correctly when the original file name is null https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#top
Show all changes 1 commit https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
dad228e Number single-delta hunks correctly when the original file name is null simpleqt Nov 4, 2026 https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/commits/dad228e7c74564c5070abcdc3c53a9dbf3698cb4
Clear filters https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Please reload this pagehttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
Please reload this pagehttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files
UnifiedDiffUtils.java https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-154afc7171f33b5cd1b431b5b88dc952bbb6da8c763201f877d7c66a28de52ab
GenerateUnifiedDiffTest.java https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-f5c3e4ea3165c22fa81255e7f4c7f38b065de67df839f27cb78a224bf0eff8ee
java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.javahttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-154afc7171f33b5cd1b431b5b88dc952bbb6da8c763201f877d7c66a28de52ab
View file https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/blob/dad228e7c74564c5070abcdc3c53a9dbf3698cb4/java-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/{{ revealButtonHref }}
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-154afc7171f33b5cd1b431b5b88dc952bbb6da8c763201f877d7c66a28de52ab
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-154afc7171f33b5cd1b431b5b88dc952bbb6da8c763201f877d7c66a28de52ab
java-diff-utils/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.javahttps://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-f5c3e4ea3165c22fa81255e7f4c7f38b065de67df839f27cb78a224bf0eff8ee
View file https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/blob/dad228e7c74564c5070abcdc3c53a9dbf3698cb4/java-diff-utils/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/{{ revealButtonHref }}
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-f5c3e4ea3165c22fa81255e7f4c7f38b065de67df839f27cb78a224bf0eff8ee
https://github-redirect.dependabot.com/java-diff-utils/java-diff-utils/pull/241/files#diff-f5c3e4ea3165c22fa81255e7f4c7f38b065de67df839f27cb78a224bf0eff8ee
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.