+ add check for null key
This commit is contained in:
Costin Leau 2010-12-21 15:46:37 +00:00
parent 9f4499cb36
commit e90f0a35e3
1 changed files with 16 additions and 1 deletions

View File

@ -68,6 +68,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
private final ExpressionEvaluator evaluator = new ExpressionEvaluator(); private final ExpressionEvaluator evaluator = new ExpressionEvaluator();
private KeyGenerator<?> keyGenerator = new DefaultKeyGenerator();
public void afterPropertiesSet() { public void afterPropertiesSet() {
if (this.cacheManager == null) { if (this.cacheManager == null) {
throw new IllegalStateException("Setting the property 'cacheManager' is required"); throw new IllegalStateException("Setting the property 'cacheManager' is required");
@ -104,6 +106,14 @@ public abstract class CacheAspectSupport implements InitializingBean {
return cacheDefinitionSource; return cacheDefinitionSource;
} }
public KeyGenerator getKeyGenerator() {
return keyGenerator;
}
public <K> void setKeyGenerator(KeyGenerator<K> keyGenerator) {
this.keyGenerator = keyGenerator;
}
/** /**
* Set multiple cache definition sources which are used to find the cache * Set multiple cache definition sources which are used to find the cache
* attributes. Will build a CompositeCachingDefinitionSource for the given sources. * attributes. Will build a CompositeCachingDefinitionSource for the given sources.
@ -135,6 +145,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
return new CacheOperationContext(definition, method, args, targetClass); return new CacheOperationContext(definition, method, args, targetClass);
} }
@SuppressWarnings("unchecked")
protected Object execute(Callable<Object> invocation, Object target, protected Object execute(Callable<Object> invocation, Object target,
Method method, Object[] args) throws Exception { Method method, Object[] args) throws Exception {
// get backing class // get backing class
@ -160,6 +171,10 @@ public abstract class CacheAspectSupport implements InitializingBean {
if (cacheDef instanceof CacheUpdateDefinition) { if (cacheDef instanceof CacheUpdateDefinition) {
Object key = context.generateKey(); Object key = context.generateKey();
if (key == null){
throw new IllegalArgumentException("Null key returned for cache definition " + cacheDef);
}
// //
// check usage of single cache // check usage of single cache
// very common case which allows for some optimization // very common case which allows for some optimization
@ -242,7 +257,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
// context passed around to avoid multiple creations // context passed around to avoid multiple creations
private final EvaluationContext evalContext; private final EvaluationContext evalContext;
private final KeyGenerator<Object> keyGenerator = new DefaultKeyGenerator(); private final KeyGenerator<?> keyGenerator = CacheAspectSupport.this.keyGenerator;
public CacheOperationContext(CacheDefinition operationDefinition, public CacheOperationContext(CacheDefinition operationDefinition,
Method method, Object[] args, Class<?> targetClass) { Method method, Object[] args, Class<?> targetClass) {