fix a bug with the full build.gradle file being cleared when block to delete is the last one in the file#444
Merged
Merged
Conversation
… delete is the last one in the file
2bb81ee to
7bc680a
Compare
OdysseusLives
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #1: The
GradleLintPatchAction.groovygenerates an invalid patch header for partial end-of-file deletions.When a lint fix deletes lines with no replacement, afterLineCount is
0and the@@hunk header is generated as+0,0:+0,0is a valid convention for complete file deletion (@@ -1,N +0,0 @@), where "0 lines at position 0" means the file is empty.For a partial deletion (@@ -184,3 +0,0 @@), it is semantically wrong — the + position should be firstLineOfContext, not 0.
JGit's ApplyCommand handles +0,0 correctly when context lines are present in the patch (it anchors on them and ignores the +l value). When there are no context lines, JGit falls back to the +l value to locate the hunk; l=0 treats the entire file as the target region, clearing it.
Issue #2. Context lines are dropped when the deleted block is preceded only by blank lines.
GradleLintPatchAction takes 3 lines before the fix as before-context, then strips leading blank ones via dropWhile:
When all 3 candidate context lines are blank (e.g. multiple blank lines separating the last block from the rest of the file), dropWhile strips them all. The patch ends up with zero context lines, exposing the +0,0 bug above.