Skip to content

Commit

Permalink
Fix ConversionService usage in config extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Sep 14, 2023
1 parent 9f77cb2 commit 121f02c
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
class MicronautLockConfigurationExtractor {
private final Duration defaultLockAtMostFor;
private final Duration defaultLockAtLeastFor;
private final ConversionService<?> conversionService;
@SuppressWarnings("rawtypes") // Micronaut 4 dropped the param type
private final ConversionService conversionService;

MicronautLockConfigurationExtractor(Duration defaultLockAtMostFor, Duration defaultLockAtLeastFor, ConversionService<?> conversionService) {
MicronautLockConfigurationExtractor(Duration defaultLockAtMostFor, Duration defaultLockAtLeastFor, @SuppressWarnings("rawtypes") ConversionService conversionService) {
this.defaultLockAtMostFor = requireNonNull(defaultLockAtMostFor);
this.defaultLockAtLeastFor = requireNonNull(defaultLockAtLeastFor);
this.conversionService = conversionService;
Expand Down Expand Up @@ -74,10 +75,11 @@ Duration getLockAtLeastFor(AnnotationValue<SchedulerLock> annotation) {
);
}

@SuppressWarnings("unchecked")
private Duration getValue(AnnotationValue<SchedulerLock> annotation, Duration defaultValue, String paramName) {
String stringValueFromAnnotation = annotation.get(paramName, String.class).orElse("");
if (StringUtils.hasText(stringValueFromAnnotation)) {
return conversionService.convert(stringValueFromAnnotation, Duration.class)
return ((Optional<Duration>) conversionService.convert(stringValueFromAnnotation, Duration.class))
.orElseThrow(() -> new IllegalArgumentException("Invalid " + paramName + " value \"" + stringValueFromAnnotation + "\" - cannot parse into duration"));
} else {
return defaultValue;
Expand Down

0 comments on commit 121f02c

Please sign in to comment.