Mutexes don't null out default arguments
Opened this issue · 2 comments
I had the following setup (extremely contrived):
@Argument(mutex = {"TWO", "THREE"})
public Integer ONE = 1;
@Argument(mutex = {"ONE", "THREE"})
public Integer TWO = null;
@Argument(mutex = {"ONE", "TWO"})
public Integer THREE = null;
Integer getNumber() {
if( ONE != null ) {
return ONE;
} else if( TWO != null ) {
return TWO;
} else {
return THREE;
}
}
I passed TWO=2
on the command line and... getNumber()
returns 1
.
I had assumed that if I set up mutexes, only one of the arguments would ever be able to be defined. I was extremely wrong and this subtly broke my application until I noticed identical results when I didn't expect them.
Two options, I think:
- If the user defines a mutex'd argument, set the other arguments all to
null
, regardless of their defaults. - Document that
mutex
only applies to what the user types, and that default arguments will remain defined even if the user defines one of the mutex.
Yeah, the intention is that mutex
applies to what the user is required to provide. FWIW, in your example, the mutex args are required, so the user is required provide at least one of them, making the initial values unnecessary. (Having said that, I take your point that the behavior wan't clear and should be documented better...)
Good point. Apparently I also assumed that if the user didn't pass anything, it'd fall back to the value that had the default defined.