Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positional parameters bug with late-resolved arity variable #2060

Closed
daisukeoto opened this issue Jul 6, 2023 · 1 comment
Closed

Positional parameters bug with late-resolved arity variable #2060

daisukeoto opened this issue Jul 6, 2023 · 1 comment
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Milestone

Comments

@daisukeoto
Copy link

daisukeoto commented Jul 6, 2023

Observed behaviour

For positional parameters, defining arity with a variable, like this: @Parameters(arity = "${xxx:-1..*}") has a bug:
regardless of the value of the system property xxx, the positional parameter is never mandatory/required.

Expected behaviour

if system property xxx is not defined, the default arity of 1..* means that at least one value is required. But this is not enforced.

How to reproduce

@Test(expected = CommandLine.MissingParameterException.class)
public void testRequiredPositionalWithUndefinedVariable() {
    class Cmd {
        @Parameters(arity = "${xxx1:-1..*}") List<String> positional;
    }
    new CommandLine(new Cmd()).parseArgs(); // should fail with missing param but doesn't
}

Analysis:

ArgSpec.required is derived from arity.min > 0, without considering whether the arity Range object has unresolved variables.
Any variables in the ArgSpec's arity are not resolved until the ArgSpec is added to its CommandSpec.
At this point, the ArgSpec's arity is replaced by a new Range object with valid values, but the ArgSpec's required attribute is not updated.

@remkop remkop added type: bug 🐛 theme: parser An issue or change related to the parser labels Jul 6, 2023
@remkop remkop added this to the 4.7.5 milestone Jul 6, 2023
@remkop remkop changed the title Positional parameters bug, with defining arity variable. Positional parameters bug with late-resolved arity variable Aug 5, 2023
@remkop remkop closed this as completed in 7ebcf1a Aug 5, 2023
@remkop
Copy link
Owner

remkop commented Aug 5, 2023

I finally got around to fixing this. Thanks again for raising this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants