Skip to content

Fix defaultValue handling for primitive Option parameters#1317

Open
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:gh-1314
Open

Fix defaultValue handling for primitive Option parameters#1317
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:gh-1314

Conversation

@therepanic
Copy link
Contributor

Fixes a case where defaultValue was ignored for primitive option types.

Closes: gh-1314

Fixes a case where defaultValue was ignored for primitive option types.

Closes: spring-projectsgh-1314

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
Comment on lines 160 to -176
Class<?> parameterType = parameterTypes[i];
// check if the option type is primitive or not
if (!parameterType.isPrimitive()) {
// try to convert default value if present
String defaultValue = optionAnnotation.defaultValue();
if (!defaultValue.isEmpty()) {
Object value = this.conversionService.convert(defaultValue, parameterType);
args.add(value);
String defaultValue = optionAnnotation.defaultValue();
if (!defaultValue.isEmpty()) {
Object value = this.conversionService.convert(defaultValue, parameterType);
args.add(value);
}
else {
if (parameterType.isPrimitive()) {
// for primitive types, add default value of the primitive
args.add(Utils.getDefaultValueForPrimitiveType(parameterType));
}
else {
// for non-primitive types, add null
args.add(null);
}
}
else {
// for primitive types, add default value of the primitive
args.add(Utils.getDefaultValueForPrimitiveType(parameterType));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't use a default value for primitives. I've changed that here, so now we use a default value for both primitives and non-primes and then check whether it's empty or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default option int value is ignored (in 4.0.1)

1 participant