Skip to content

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

Closed

Description

@spring-projects-issues

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:

Activity

  1. spring-projects-issues commented on Jun 25, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Phil Webb commented

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

  2. added
    type: bug
    in: core
    status: duplicate
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions