Method execution should not error without value
- Do npe check when getting class type out from incoming value. - Backport #572 - Fix #573
This commit is contained in:
@@ -183,8 +183,10 @@ public interface CommandExecution {
|
||||
if (parameterName == null) {
|
||||
return false;
|
||||
}
|
||||
Class<?> sourceType = paramValues.get(parameterName) != null ? paramValues.get(parameterName).getClass()
|
||||
: null;
|
||||
return paramValues.containsKey(parameterName) && conversionService
|
||||
.canConvert(paramValues.get(parameterName).getClass(), parameter.getParameterType());
|
||||
.canConvert(sourceType, parameter.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -100,6 +100,26 @@ public class CommandExecutionTests extends AbstractCommandTests {
|
||||
assertThat(pojo1.method1Ctx).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodArgWithoutValue() {
|
||||
CommandRegistration r1 = CommandRegistration.builder()
|
||||
.command("command1")
|
||||
.description("help")
|
||||
.withOption()
|
||||
.longNames("arg1")
|
||||
.description("some arg1")
|
||||
.position(0)
|
||||
.arity(OptionArity.EXACTLY_ONE)
|
||||
.and()
|
||||
.withTarget()
|
||||
.method(pojo1, "method4")
|
||||
.and()
|
||||
.build();
|
||||
execution.evaluate(r1, new String[]{"--arg1"});
|
||||
assertThat(pojo1.method4Count).isEqualTo(1);
|
||||
assertThat(pojo1.method4Arg1).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodSinglePositionalArgs() {
|
||||
CommandRegistration r1 = CommandRegistration.builder()
|
||||
|
||||
Reference in New Issue
Block a user