New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring cache defaults to hashcode based cache key for multiple arguments [SPR-10688] #15316

spring-issuemaster opened this Issue Jun 25, 2013 · 1 comment


None yet
2 participants
Copy link

spring-issuemaster commented Jun 25, 2013

Lance S opened SPR-10688 and commented

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(
	at org.junit.Assert.assertEquals(


Issue Links:

  • #14870 Cacheable key collision with DefaultKeyGenerator ("duplicates")

This comment has been minimized.

Copy link

spring-issuemaster commented Jun 25, 2013

Phil Webb commented

This issue has recently been addressed with #14870 and the default behavior will change with Spring 4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment