diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java index a3f8791a55..9637abc94b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java @@ -92,12 +92,12 @@ public class BeanFactoryAnnotationUtils { return matchingBean; } else if (bf.containsBean(qualifier)) { - // Fallback: target bean at least found by bean name. + // Fallback: target bean at least found by bean name - probably a manually registered singleton. return bf.getBean(qualifier, beanType); } else { throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() + - " bean found for qualifier '" + qualifier + "' - neither qualifier " + "match nor bean name match!"); + " bean found for qualifier '" + qualifier + "' - neither qualifier match nor bean name match!"); } } @@ -133,7 +133,7 @@ public class BeanFactoryAnnotationUtils { } } catch (NoSuchBeanDefinitionException ex) { - // ignore - can't compare qualifiers for a manually registered singleton object + // Ignore - can't compare qualifiers for a manually registered singleton object } } return false; diff --git a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java index 6acc2aad0b..302e513fcb 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java @@ -46,19 +46,22 @@ public class GuavaCache implements Cache { /** - * Create a {@link GuavaCache} instance. + * Create a {@link GuavaCache} instance with the specified name and the + * given internal {@link com.google.common.cache.Cache} to use. * @param name the name of the cache - * @param cache backing Guava Cache instance + * @param cache the backing Guava Cache instance */ public GuavaCache(String name, com.google.common.cache.Cache cache) { this(name, cache, true); } /** - * Create a {@link GuavaCache} instance. + * Create a {@link GuavaCache} instance with the specified name and the + * given internal {@link com.google.common.cache.Cache} to use. * @param name the name of the cache - * @param cache backing Guava Cache instance - * @param allowNullValues whether to accept and convert null values for this cache + * @param cache the backing Guava Cache instance + * @param allowNullValues whether to accept and convert {@code null} + * values for this cache */ public GuavaCache(String name, com.google.common.cache.Cache cache, boolean allowNullValues) { Assert.notNull(name, "Name must not be null"); @@ -110,8 +113,9 @@ public class GuavaCache implements Cache { PutIfAbsentCallable callable = new PutIfAbsentCallable(value); Object result = this.cache.get(key, callable); return (callable.called ? null : toWrapper(result)); - } catch (ExecutionException e) { - throw new IllegalArgumentException(e); + } + catch (ExecutionException ex) { + throw new IllegalStateException(ex); } } @@ -161,19 +165,21 @@ public class GuavaCache implements Cache { private static class NullHolder implements Serializable { } + private class PutIfAbsentCallable implements Callable { - private boolean called; private final Object value; - private PutIfAbsentCallable(Object value) { + private boolean called; + + public PutIfAbsentCallable(Object value) { this.value = value; } @Override public Object call() throws Exception { - called = true; - return toStoreValue(value); + this.called = true; + return toStoreValue(this.value); } } diff --git a/spring-context/src/main/java/org/springframework/cache/Cache.java b/spring-context/src/main/java/org/springframework/cache/Cache.java index 61058eace1..8a8ee5537c 100644 --- a/spring-context/src/main/java/org/springframework/cache/Cache.java +++ b/spring-context/src/main/java/org/springframework/cache/Cache.java @@ -81,8 +81,8 @@ public interface Cache { void put(Object key, Object value); /** - * Atomically associate the specified value with the specified key in this cache if - * it is not set already. + * Atomically associate the specified value with the specified key in this cache + * if it is not set already. *

This is equivalent to: *


 	 * Object existingValue = cache.get(key);
@@ -93,17 +93,18 @@ public interface Cache {
 	 *     return existingValue;
 	 * }
 	 * 
- * except that the action is performed atomically. While all known providers are - * able to perform the put atomically, the returned value may be retrieved after - * the attempt to put (i.e. in a non atomic way). Check the documentation of - * the native cache implementation that you are using for more details. + * except that the action is performed atomically. While all out-of-the-box + * {@link CacheManager} implementations are able to perform the put atomically, + * the operation may also be implemented in two steps, e.g. with a check for + * presence and a subsequent put, in a non-atomic way. Check the documentation + * of the native cache implementation that you are using for more details. * @param key the key with which the specified value is to be associated * @param value the value to be associated with the specified key - * @return the value to which this cache maps the specified key (which may - * be {@code null} itself), or also {@code null} if the cache did not contain - * any mapping for that key prior to this call. Returning {@code null} is - * therefore an indicator that the given {@code value} has been associated - * with the key + * @return the value to which this cache maps the specified key (which may be + * {@code null} itself), or also {@code null} if the cache did not contain any + * mapping for that key prior to this call. Returning {@code null} is therefore + * an indicator that the given {@code value} has been associated with the key. + * @since 4.1 */ ValueWrapper putIfAbsent(Object key, Object value); diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index 8601245ea8..07f50d7497 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -63,7 +63,8 @@ public class ConcurrentMapCache implements Cache { /** * Create a new ConcurrentMapCache with the specified name. * @param name the name of the cache - * @param allowNullValues whether to accept and convert null values for this cache + * @param allowNullValues whether to accept and convert {@code null} + * values for this cache */ public ConcurrentMapCache(String name, boolean allowNullValues) { this(name, new ConcurrentHashMap(256), allowNullValues); @@ -71,7 +72,7 @@ public class ConcurrentMapCache implements Cache { /** * Create a new ConcurrentMapCache with the specified name and the - * given internal ConcurrentMap to use. + * given internal {@link ConcurrentMap} to use. * @param name the name of the cache * @param store the ConcurrentMap to use as an internal store * @param allowNullValues whether to allow {@code null} values