Skip to content

floor the options column at the Options header width - #443

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:help-since-header-width
Open

rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:help-since-header-width

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

appendOptions sizes the options column only from the rendered option entries and never from the header row, so once every option is narrower than the Options header the gap it computes for the header line, max - maxSince - HEADER_OPTIONS.length() + leftPad, is negative and createPadding runs new char[-3]. With setShowSince(true) that makes printHelp throw NegativeArraySizeException for something as ordinary as an app whose flags are -h and -v. Found while fuzzing the help output across option widths and pad settings.

determineMaxSinceLength already floors the since column at the width of the Since header; the option column just needs the same floor, so max now starts there when showSince is set. Keeping the bound next to the arithmetic that uses it leaves every createPadding argument in the method non-negative, and output is unchanged for any Options whose column was already that wide.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code helped write the fix, the test, and this description.
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

appendOptions sized the column only from the option entries, so a column narrower than the Options header made the header gap negative and createPadding allocated a negative-length array.
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.

1 participant