Closed
Description
Craig opened SPR-14853 and commented
#18804 is still reproducible if "sync=true" is set on the @Cacheable
annotation.
For example, in
class MyServiceImpl implements MyService {
private static final String CACHE_NAME = "itemCache";
@Override
@Cacheable(value=CACHE_NAME, sync=)
public Optional<Item> findById(Long id) {
// access the repository to retrieve the item
}
@Override
@CachePut(cacheNames = CACHE_NAME, key = "#item.id")
public Item insertItem(Item item) {
...
}
}
a ClassCastException is thrown.
The problem is in https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java#L358 - when sync=true, a diffferent path is taken that does not do the Optional wrapping/unwrapping which takes place at https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java#L404
Affects: 4.3.3
Issue Links:
- Allow @Cacheable method to return java.util.Optional variant of cached value [SPR-14230] #18804 Allow
@Cacheable
method to return java.util.Optional variant of cached value
1 votes, 3 watchers