Skip to content

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

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

Closed
spring-projects-issues opened this issue Jun 25, 2013 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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(Assert.java:123)
	at org.junit.Assert.assertEquals(Assert.java:145)
	at foo.bar.SpringCacheBrokenTest.testCache(SpringCacheBrokenTest.java:52)

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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.

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants