Skip to content

Commands fail in 4.0 if no short name or long name are specifiedΒ #1261

Closed

Description

@ThomasVitale

When upgrading to Spring Shell 4.0, all annotated command options that don't have a short name or long name specified fail the application initialisation.

If that change was intentional, it would be great to highlight it in the migration guide as a breaking change and update the JavaDocs as the @Option annotation states that those two arguments are optional.

Still, it would be great to restore the previous behaviour where the Java property name was used as the long name by default. That would be in line with other Spring projects like Spring MVC, where the @RequestParam doesn't require specifying a name if it matches the Java property name.

A command definition like the following with Spring Shell 3.4:

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.") String myOption,
    ) {
        ...
    }

would need to change to the following in 4.0:

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.",  longName = "myOption") String myOption,
    ) {
        ...
    }

It's counterintuitive that the longName is not needed if a shortName is specified, since the shortName should be an additional way on top of the longName.

This works in 4.0 (no need to specify longName because a shortName is specified):

    @Command(name = "test", description = "Test command.")
    public void build(
        @Option(description = "Some option.",  shortName = "o") String myOption,
    ) {
        ...
    }

I'm available to help with a potential PR.

Activity

  1. fmbenhassine commented on Jan 29, 2026

    @fmbenhassine
    Contributor

    Thank you for reporting this, it was not intentional. The current behaviour is indeed incorrect.

    Still, it would be great to restore the previous behaviour where the Java property name was used as the long name by default.

    I agree. I will make the option name default to the parameter name when no longName is provided.

    It's counterintuitive that the longName is not needed if a shortName is specified, since the shortName should be an additional way on top of the longName.

    Same here. This makes sense and I think I just missed that when I ported things from v3.

    I will plan the fix for 4.0.1.

  2. added and removed
    status/need-triageTeam needs to triage and take a first look
    on Jan 29, 2026
  3. added this to the 4.0.1 milestone on Jan 29, 2026
  4. czpilar commented on Jan 29, 2026

    @czpilar
    Contributor

    Fixed in PR #1303

  5. added a commit that references this issue on Jan 30, 2026
    6b1e701
  6. ThomasVitale commented on Jan 30, 2026

    @ThomasVitale
    ContributorAuthor

    Thank you both!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions