diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java index 38a93b8827..f5967110dc 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,13 +41,15 @@ public class EhCacheCache implements Cache { /** * Create an {@link EhCacheCache} instance. - * @param ehcache backing Ehcache instance + * @param ehcache the backing Ehcache instance */ public EhCacheCache(Ehcache ehcache) { Assert.notNull(ehcache, "Ehcache must not be null"); Status status = ehcache.getStatus(); - Assert.isTrue(Status.STATUS_ALIVE.equals(status), - "An 'alive' Ehcache is required - current cache is " + status.toString()); + if (!Status.STATUS_ALIVE.equals(status)) { + throw new IllegalArgumentException( + "An 'alive' Ehcache is required - current cache is " + status.toString()); + } this.cache = ehcache; } @@ -78,7 +80,7 @@ public class EhCacheCache implements Cache { else { this.cache.acquireWriteLockOnKey(key); try { - element = lookup(key); // One more attempt with the write lock + element = lookup(key); // one more attempt with the write lock if (element != null) { return (T) element.getObjectValue(); } @@ -111,7 +113,8 @@ public class EhCacheCache implements Cache { Element element = this.cache.get(key); Object value = (element != null ? element.getObjectValue() : null); if (value != null && type != null && !type.isInstance(value)) { - throw new IllegalStateException("Cached value is not of required type [" + type.getName() + "]: " + value); + throw new IllegalStateException( + "Cached value is not of required type [" + type.getName() + "]: " + value); } return (T) value; } diff --git a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java index 82fbd99e83..7fc59baebf 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java +++ b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,8 @@ public abstract class AbstractValueAdaptingCache implements Cache { public T get(Object key, Class type) { Object value = fromStoreValue(lookup(key)); if (value != null && type != null && !type.isInstance(value)) { - throw new IllegalStateException("Cached value is not of required type [" + type.getName() + "]: " + value); + throw new IllegalStateException( + "Cached value is not of required type [" + type.getName() + "]: " + value); } return (T) value; } @@ -70,7 +71,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { /** * Perform an actual lookup in the underlying store. * @param key the key whose associated value is to be returned - * @return the raw store value for the key + * @return the raw store value for the key, or {@code null} if none */ protected abstract Object lookup(Object key);