Repository navigation
Report a short diff command line as a parser error instead of crashing - #245
Merged
wumpz merged 1 commit intoDec 3, 2026
Merged
Conversation
UnifiedDiffReader.parseFileNames read split[2] and split[3] without checking the token count, so a diff command line with fewer than four words (for example "diff a b") threw ArrayIndexOutOfBoundsException from inside parseUnifiedDiff instead of the documented UnifiedDiffParserException. Throw UnifiedDiffParserException when the line does not carry both file names. Adds regression tests that fail before this change.
Collaborator
|
Thx for using java-diff-utils. |
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.
UnifiedDiffReader.parseFileNamessplits thediffcommand line on spaces and readssplit[2]andsplit[3]without checking how many tokens there are. A command line with fewer than four words therefore throwsArrayIndexOutOfBoundsExceptionfrom insideparseUnifiedDiff, rather than theUnifiedDiffParserExceptionthe reader uses for malformed input:Since
DIFF_COMMANDmatches any line that starts withdifffollowed by whitespace, any such short or free-text header line hits this path.This change throws
UnifiedDiffParserExceptionwhen the line does not carry both file names, leaving the parsing of well-formed command lines (diff -u a b,diff --git a/x b/y) unchanged.Added two regression tests in
UnifiedDiffReaderTest(directparseFileNamescall and the fullparseUnifiedDiffpath); both fail on master withArrayIndexOutOfBoundsExceptionand pass with the change.Validation on Temurin/OpenJDK:
mvn -pl java-diff-utils testpasses (170 run, 0 failures, 3 pre-existing skips);spotless:checkandcheckstyle:checkreport no new findings.