Skip to content

Account for skipped delimiters when consuming fixed-arity values - #621

Open
umtong wants to merge 2 commits into
cbeust:masterfrom
umtong:fix/fixed-arity-delimiter-count
Open

umtong wants to merge 2 commits into
cbeust:masterfrom
umtong:fix/fixed-arity-delimiter-count

Conversation

@umtong

@umtong umtong commented Oct 25, 2026 •

Copy link
Copy Markdown

processFixedArity skips an immediate -- before an option value, but omits that token from its bounds check and consumed-token count. As a result, --value -- literal tail assigns literal to 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 throws ArrayIndexOutOfBoundsException.

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 ParameterException path.

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=plain passes 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).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 ParameterException handling 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

@mkarg

mkarg commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@umtong Can you please file a bug report describing the original fault?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants