Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

required Boolean with non-default value

Open
#949 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
cli

Research direction

Start by reproducing the annotated command examples using Boolean and boolean, then inspect how @Option required, defaultValue, and help-menu optionality are processed. Compare omitted options with explicit true and false values; done means a required Boolean option has no implicit choice and the help output and command validation consistently reflect that.

Written by the indexing model from the issue text.

Description

status/need-triage

spring shell version: 3.1.6

In one of my commands, I want to make sure that the end-user specifically indicates whether they either want A or B by using a Boolean. I don't want to make the choice for the end user.

When I add the following @Option on my command:

@Option(required = true, description = "Description", longNames = "Some long name")  Boolean booleanOption

Spring Shell, automatically transforms the booleanOption to defaultValue false. The help menu of the command indicates that the booleanOption is optional.

When transforming into

@Option(required = true, description = "Description", longNames = "Some long name")  boolean booleanOption

Still, the help menu indicates the booleanOption as optional. I assume for 2 reasons that this should not be the case: (1) it is a boolean and not Boolean. (2) required is explicitly set to true. The defaultValue is again false.

Setting the defaultValue to 'true' explicitly seems to be working.

@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "true")boolean booleanOption

It will show that the boolean is optional, but the default value will be true.

But again, I didn't want to choose for the user. I want the end user to articulate their choice when doing a command specifically.

If I write:

@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "")Boolean booleanOption

Or

@Option(required = true, description = "Description", longNames = "Some long name", defaultValue = "null")Boolean booleanOption

The defaultValue still translates to false (while as a Boolean I would expect it to be able to be null).

Is this the intended behavior?

Dominant language
Java
Stars
826
Forks
405
Avg merge
6d 9h
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-shell

All issues in spring-projects/spring-shell

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.