You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spring cache defaults to hashcode based cache key for multiple arguments [SPR-10688] #15316
If I add a @Cacheable("cachename") annotation to a method with multiple arguments and I don't specify a key, Spring will create a cache key for me. This cache key is a hash of the arguments. Since a hash is not guaranteed to be unique, I think that this is a dangerous default which will cause errors (although the errors will be rare).
For example:
Long.valueOf(0) and Long.valueOf(-1) both have 0 as their hashcode.
I have attached a failing test case. The test case fails the final assertion
org.junit.ComparisonFailure: expected:<0:[-1]> but was:<0:[0]>
at org.junit.Assert.assertEquals(Assert.java:123)
at org.junit.Assert.assertEquals(Assert.java:145)
at foo.bar.SpringCacheBrokenTest.testCache(SpringCacheBrokenTest.java:52)
Activity
spring-projects-issues commentedon Jun 25, 2013
Phil Webb commented
This issue has recently been addressed with #14870 and the default behavior will change with Spring 4.0.