提交 e1d19d6c 编写于 作者: C Costin Leau

SPR-8238

+ add handling for null arguments to prevent NPE in default key generation
上级 d14c7f2d
...@@ -22,7 +22,7 @@ import org.springframework.cache.KeyGenerator; ...@@ -22,7 +22,7 @@ import org.springframework.cache.KeyGenerator;
/** /**
* Default key generator. Returns 0 if no param is given, the param itself if only one is given or a hash code computed * Default key generator. Returns 0 if no param is given, the param itself if only one is given or a hash code computed
* from all given params hash code. * from all given params hash code. Uses a constant (53) for null objects.
* *
* @author Costin Leau * @author Costin Leau
*/ */
...@@ -30,7 +30,7 @@ public class DefaultKeyGenerator implements KeyGenerator<Object> { ...@@ -30,7 +30,7 @@ public class DefaultKeyGenerator implements KeyGenerator<Object> {
public Object extract(Object target, Method method, Object... params) { public Object extract(Object target, Method method, Object... params) {
if (params.length == 1) { if (params.length == 1) {
return params[0]; return (params[0] == null ? 53 : params[0]);
} }
if (params.length == 0) { if (params.length == 0) {
...@@ -40,7 +40,7 @@ public class DefaultKeyGenerator implements KeyGenerator<Object> { ...@@ -40,7 +40,7 @@ public class DefaultKeyGenerator implements KeyGenerator<Object> {
int hashCode = 17; int hashCode = 17;
for (Object object : params) { for (Object object : params) {
hashCode = 31 * hashCode + object.hashCode(); hashCode = 31 * hashCode + (object == null ? 53 : object.hashCode());
} }
return Integer.valueOf(hashCode); return Integer.valueOf(hashCode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册