From 67f184293b94c076b0474231f739a74f42d5ffa8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 10 Dec 2014 14:34:11 +0100 Subject: [PATCH] Improve performance of generateKey Only compute the error message to display when the generated key is actually null instead of using Assert.notNull as the cache operation 'toString()' method is non trivial and gets computed regardless of the result. Issue: SPR-12527 --- .../cache/interceptor/CacheAspectSupport.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index 676a194b6b..779dfbbcde 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -477,8 +477,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private Object generateKey(CacheOperationContext context, Object result) { Object key = context.generateKey(result); - Assert.notNull(key, "Null key returned for cache operation (maybe you are using named params " + - "on classes without debug info?) " + context.metadata.operation); + if (key == null) { + throw new IllegalArgumentException("Null key returned for cache operation (maybe you are " + + "using named params on classes without debug info?) " + context.metadata.operation); + } if (logger.isTraceEnabled()) { logger.trace("Computed cache key " + key + " for operation " + context.metadata.operation); }