Skip to content

Commit

Permalink
Fix casting issue (#1084)
Browse files Browse the repository at this point in the history
In IntelliJ, the existing combination of raw types, casting, and lambdas often produces spurious compilation errors. This PR introduces a solution which hides the unsafe cast in a single method, and also uses `Map.putIfAbsent` to avoid constructing a lambda for this case.
  • Loading branch information
dmlloyd authored Jan 11, 2024
1 parent b36238a commit 883c97f
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,21 @@ public <T> T convert(String value, Class<T> asType) {
return value != null ? requireConverter(asType).convert(value) : null;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private <T> Converter<Optional<T>> getOptionalConverter(Class<T> asType) {
return optionalConverters.computeIfAbsent(asType,
clazz -> newOptionalConverter(requireConverter((Class) clazz)));
Converter<Optional<T>> converter = recast(optionalConverters.get(asType));
if (converter == null) {
converter = newOptionalConverter(requireConverter(asType));
Converter<Optional<T>> appearing = recast(optionalConverters.putIfAbsent(asType, recast(converter)));
if (appearing != null) {
converter = appearing;
}
}
return converter;
}

@SuppressWarnings("unchecked")
private static <T> T recast(Object obj) {
return (T) obj;
}

@Deprecated // binary-compatibility bridge method for Quarkus
Expand Down

0 comments on commit 883c97f

Please sign in to comment.