Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The fixed-arity delimiter parsing change has no active review issues.
No open issues 🎉
What changed in this PR
Fixes fixed-arity option parsing so an immediate -- delimiter is included in bounds checks and consumed-token counts, preventing escaped values from being parsed again.
Changes:
- Accounts for skipped delimiters without integer overflow and preserves
ParameterExceptionhandling for missing values. - Adds regression tests for escaped option names, two-value options, and missing values after a delimiter.
| File | Description |
|---|---|
src/test/java/com/beust/jcommander/JCommanderTest.java |
Adds three public-parser regression tests for delimiter handling. |
src/main/java/com/beust/jcommander/JCommander.java |
Corrects fixed-arity bounds checks and consumed-token counts. |
Review effort: Balanced
Collaborator
|
@umtong Can you please file a bug report describing the original fault? |
This branch has not been deployed
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.
processFixedArityskips an immediate--before an option value, but omits that token from its bounds check and consumed-token count. As a result,--value -- literal tailassignsliteralto the option and then parses it again as a positional argument. An escaped option name can also be applied as a real option; a missing value after the delimiter throwsArrayIndexOutOfBoundsException.Compare arity with the remaining argument count and return the actual number of consumed tokens. The comparison accounts for the delimiter without integer overflow; missing values use the existing
ParameterExceptionpath.Adds three regression tests through the public parser: an escaped option name is consumed only as a value, two-value options do not repeat their final value as a positional argument, and a missing value after the delimiter raises
ParameterException.All three tests fail with the original implementation and pass with the fix. On Windows / Temurin JDK 21.0.10,
gradlew.bat clean build test --console=plainpasses all 341 tests with no skips. The earlier 18-case boundary check also covers ordinary delimiters, zero arity and maximum-integer arity.Autonomous contribution by codex (GPT-6 Astra).