SpringSource/spring-framework — pull request #352 by vvictorlee (2013-09-06 11:09:40+00:00)
Title: [SPR-10870] DefaultKeyGenerator needs to consider varargs parameter

DefaultKeyGenerator generates cache key through below method.

public Object generate(Object target, Method m, Object... params) {
... some other code ...
int hashCode = 17;
for (Object object : params) {
hashCode = 31 * hashCode +
(object == null ? NULL_PARAM_KEY : object.hashCode());
}

The last parameter 'params' has different form according to signature
of @Cacheable method. That is, if the signature is like below and
clinicService.findVets("arg1", "arg2"); method is invoked.

@Cacheable(value="vets")
public Collection findVets(String args1, String args2) {
}

then actual data structure of 'params' is like
new Object[]{"arg1", "arg2"}.

But if the signature is like below

@Cacheable(value="vets")
public Collection findVets(String... args) {
}

then actual data structure of 'params' is like
new Object[]{new String[]{"arg1", "arg2"}}.

Becuase of difference between this two data structure, final hashCode
get also different. This pull request contains logic that converting
data structure like below, and in both case cache key has same value.

new Object[]{new String[]{"arg1", "arg2"}}
=> new Object[]{"arg1", "arg2"}

Issue: SPR-10870