diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java index 49b10dd35..c7982a24a 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java @@ -615,10 +615,21 @@ public T convert(String value, Class asType) { return value != null ? requireConverter(asType).convert(value) : null; } - @SuppressWarnings({ "unchecked", "rawtypes" }) private Converter> getOptionalConverter(Class asType) { - return optionalConverters.computeIfAbsent(asType, - clazz -> newOptionalConverter(requireConverter((Class) clazz))); + Converter> converter = recast(optionalConverters.get(asType)); + if (converter == null) { + converter = newOptionalConverter(requireConverter(asType)); + Converter> appearing = recast(optionalConverters.putIfAbsent(asType, recast(converter))); + if (appearing != null) { + converter = appearing; + } + } + return converter; + } + + @SuppressWarnings("unchecked") + private static T recast(Object obj) { + return (T) obj; } @Deprecated // binary-compatibility bridge method for Quarkus