DATACMNS-1101 - Use dedicated type to cache custom conversion targets without requested target type.
We now use a marker interface to store cache hits for conversion targets without requesting a conversion target in the conversion query. The dedicated marker type has an individual cache view and does not interfere with other types. Previously we used Object as cache key which caused false positives due to assignability checks. If an earlier conversion query with a requested target type yielded a hit (e.g. negative hit), subsequent queries without a target type received the same answer. This might happen although the non-cached answer would return a different result.
This commit is contained in:
committed by
Oliver Gierke
parent
f6a6565638
commit
3dbbb15672
@@ -372,7 +372,7 @@ public class CustomConversions {
|
||||
*/
|
||||
public Optional<Class<?>> computeIfAbsent(Class<?> sourceType,
|
||||
Function<ConvertiblePair, Optional<Class<?>>> mappingFunction) {
|
||||
return computeIfAbsent(sourceType, Object.class, mappingFunction);
|
||||
return computeIfAbsent(sourceType, AbsentTargetTypeMarker.class, mappingFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,6 +391,11 @@ public class CustomConversions {
|
||||
TargetTypes targetTypes = customReadTargetTypes.computeIfAbsent(sourceType, TargetTypes::new);
|
||||
return targetTypes.computeIfAbsent(targetType, mappingFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marker type for absent target type caching.
|
||||
*/
|
||||
interface AbsentTargetTypeMarker {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user