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
Suppose that I have this converter which takes a String and attempts conversion into an Index - which is basically a wrapper around an int:
publicclassIndexConverterimplementsIStringConverter<Index> {
@OverridepublicIndexconvert(Stringvalue) {
if (!StringUtil.isNonZeroUnsignedInteger(value)) {
thrownewParameterException("The index must be a non-zero unsigned integer.");
}
returnIndex.fromOneBased(Integer.parseInt(value));
}
}
However, if I define a parameter in my command class like so, and I attempt to let JCommander parse the command <command word> 123 abc, now I get the ParameterException thrown because the "abc" is not an integer - but should JCommander instead realize that the arity of 2 is incorrect before attempting conversion?:
My rationale for raising this issue is that the exception message is of the wrong specificity - the exception from the failed conversion has higher priority than the exception from the arity.
This is behavior is undesirable for my use case as it's more important to reject the incorrect arity than to inform the user of a failed conversion.
Could there be a way to configure JCommander to validate arities before conversions?
The text was updated successfully, but these errors were encountered:
Suppose that I have this converter which takes a String and attempts conversion into an
Index
- which is basically a wrapper around anint
:However, if I define a parameter in my command class like so, and I attempt to let JCommander parse the command
<command word> 123 abc
, now I get theParameterException
thrown because the "abc" is not an integer - but should JCommander instead realize that the arity of 2 is incorrect before attempting conversion?:My rationale for raising this issue is that the exception message is of the wrong specificity - the exception from the failed conversion has higher priority than the exception from the arity.
This is behavior is undesirable for my use case as it's more important to reject the incorrect arity than to inform the user of a failed conversion.
Could there be a way to configure JCommander to validate arities before conversions?
The text was updated successfully, but these errors were encountered: