You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
publicvoidtestRequiredPositionalWithUndefinedVariable() {
classCmd {
@Parameters(arity = "${xxx1:-1..*}") List<String> positional;
}
newCommandLine(newCmd()).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.
The text was updated successfully, but these errors were encountered:
remkop
changed the title
Positional parameters bug, with defining arity variable.
Positional parameters bug with late-resolved arity variable
Aug 5, 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
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.
The text was updated successfully, but these errors were encountered: