File tree 2 files changed +23
-1
lines changed
main/java/org/springframework/shell/command
test/java/org/springframework/shell/command
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -183,8 +183,10 @@ public boolean supportsParameter(MethodParameter parameter) {
183
183
if (parameterName == null ) {
184
184
return false ;
185
185
}
186
+ Class <?> sourceType = paramValues .get (parameterName ) != null ? paramValues .get (parameterName ).getClass ()
187
+ : null ;
186
188
return paramValues .containsKey (parameterName ) && conversionService
187
- .canConvert (paramValues . get ( parameterName ). getClass () , parameter .getParameterType ());
189
+ .canConvert (sourceType , parameter .getParameterType ());
188
190
}
189
191
190
192
@ Override
Original file line number Diff line number Diff line change @@ -100,6 +100,26 @@ public void testMethodExecution2() {
100
100
assertThat (pojo1 .method1Ctx ).isNotNull ();
101
101
}
102
102
103
+ @ Test
104
+ public void testMethodArgWithoutValue () {
105
+ CommandRegistration r1 = CommandRegistration .builder ()
106
+ .command ("command1" )
107
+ .description ("help" )
108
+ .withOption ()
109
+ .longNames ("arg1" )
110
+ .description ("some arg1" )
111
+ .position (0 )
112
+ .arity (OptionArity .EXACTLY_ONE )
113
+ .and ()
114
+ .withTarget ()
115
+ .method (pojo1 , "method4" )
116
+ .and ()
117
+ .build ();
118
+ execution .evaluate (r1 , new String []{"--arg1" });
119
+ assertThat (pojo1 .method4Count ).isEqualTo (1 );
120
+ assertThat (pojo1 .method4Arg1 ).isNull ();
121
+ }
122
+
103
123
@ Test
104
124
public void testMethodSinglePositionalArgs () {
105
125
CommandRegistration r1 = CommandRegistration .builder ()
You can’t perform that action at this time.
0 commit comments