-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement
Milestone
Description
member sound opened SPR-13758 and commented
If you run the following code, the @Cachable method will not always return the same results (but it should).
@RestController
@RequestMapping("/rest")
public class TestRunner {
@Autowired
private TestController controller;
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/test", method = RequestMethod.GET)
@PostConstruct
public void testCaching() {
controller.test();
controller.test();
}
}
public class TestService {
@Cacheable("test")
public Set<String> get() {
Set<String> set = new HashSet<>();
set.add("ASD");
set.add("123");
return set;
}
}
@Controller
public class TestController {
@Autowired
private TestService testService;
public void test() {
Set<String> list = testService.get();
Assert.assertEquals(2, list.size()); //fails when run the 2nd time with: junit.framework.AssertionFailedError: expected:<2> but was:<1>
Iterator<String> it = list.iterator();
it.next();
it.remove(); //removes the first item
}
}
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
Steps to reproduce the error: run http://localhost:8080/rest/test
I noticed that if I use a @PostConstruct method running the controller.test() method twice, this would not cause the error. So the application starts up fine, but invoking the servlet explicit triggers the failure.
Affects: 4.2.3
Issue Links:
- ConcurrentMapCacheManager's storeByValue does not pick up ClassLoader [SPR-14314] #18886 ConcurrentMapCacheManager's storeByValue does not pick up ClassLoader
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancementA general enhancement