In the DefaultParser class, we are using handleOption method which is defined
as following
privatevoidhandleOption(Optionoption)throwsParseException{
// check the previous option before handling the next one
checkRequiredArgs();
option=(Option)option.clone();
updateRequiredOptions(option);
cmd.addOption(option);
if(option.hasArg()){
currentOption=option;
}else{
currentOption=null;
}
}
option.hasArg() returns true only when argCount is greater than 0 or is
UNLIMITED_VALUES.
But, if our option is built with optionalArg(true), then argCount seems
UNINITIALIZED.
So, if our option is built with optionalArg(true), handleOption(option) sets
currentOption to null which we aren't handling at DefaultParser class LIne 484