diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index 515f1621ad..6a5a3cf700 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -22,7 +22,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -93,7 +92,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * List of Advisors. If an Advice is added, it will be wrapped * in an Advisor before being added to this List. */ - private List advisors = new LinkedList(); + private List advisors = new ArrayList(); /** * Array updated on changes to the advisors list, which is easier @@ -480,7 +479,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * for the given method, based on this configuration. * @param method the proxied method * @param targetClass the target class - * @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) + * @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) */ public List getInterceptorsAndDynamicInterceptionAdvice(Method method, Class targetClass) { MethodCacheKey cacheKey = new MethodCacheKey(method); @@ -534,7 +533,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { /** * Build a configuration-only copy of this AdvisedSupport, - * replacing the TargetSource + * replacing the TargetSource. */ AdvisedSupport getConfigurationOnlyCopy() { AdvisedSupport copy = new AdvisedSupport(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java index 740a7bb8ff..e1e0cdfb88 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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,9 +62,9 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ // Add it conditionally. PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor; if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) { - MethodInterceptor[] interceptors = registry.getInterceptors(advisor); MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher(); if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) { + MethodInterceptor[] interceptors = registry.getInterceptors(advisor); if (mm.isRuntime()) { // Creating a new object instance in the getInterceptors() method // isn't a problem as we normally cache created chains. @@ -98,8 +98,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ * Determine whether the Advisors contain matching introductions. */ private static boolean hasMatchingIntroductions(Advised config, Class actualClass) { - for (int i = 0; i < config.getAdvisors().length; i++) { - Advisor advisor = config.getAdvisors()[i]; + for (Advisor advisor : config.getAdvisors()) { if (advisor instanceof IntroductionAdvisor) { IntroductionAdvisor ia = (IntroductionAdvisor) advisor; if (ia.getClassFilter().matches(actualClass)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java index 9eacf479ba..97ff108d83 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -31,15 +31,15 @@ import org.springframework.aop.Advisor; public interface AdvisorAdapterRegistry { /** - * Return an Advisor wrapping the given advice. + * Return an {@link Advisor} wrapping the given advice. *

Should by default at least support * {@link org.aopalliance.intercept.MethodInterceptor}, * {@link org.springframework.aop.MethodBeforeAdvice}, * {@link org.springframework.aop.AfterReturningAdvice}, * {@link org.springframework.aop.ThrowsAdvice}. * @param advice object that should be an advice - * @return an Advisor wrapping the given advice. Never returns {@code null}. - * If the advice parameter is an Advisor, return it. + * @return an Advisor wrapping the given advice (never {@code null}; + * if the advice parameter is an Advisor, it is to be returned as-is) * @throws UnknownAdviceTypeException if no registered advisor adapter * can wrap the supposed advice */ @@ -48,21 +48,20 @@ public interface AdvisorAdapterRegistry { /** * Return an array of AOP Alliance MethodInterceptors to allow use of the * given Advisor in an interception-based framework. - *

Don't worry about the pointcut associated with the Advisor, - * if it's a PointcutAdvisor: just return an interceptor. + *

Don't worry about the pointcut associated with the {@link Advisor}, if it is + * a {@link org.springframework.aop.PointcutAdvisor}: just return an interceptor. * @param advisor Advisor to find an interceptor for * @return an array of MethodInterceptors to expose this Advisor's behavior * @throws UnknownAdviceTypeException if the Advisor type is - * not understood by any registered AdvisorAdapter. + * not understood by any registered AdvisorAdapter */ MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException; /** - * Register the given AdvisorAdapter. Note that it is not necessary to register + * Register the given {@link AdvisorAdapter}. Note that it is not necessary to register * adapters for an AOP Alliance Interceptors or Spring Advices: these must be - * automatically recognized by an AdvisorAdapterRegistry implementation. - * @param adapter AdvisorAdapter that understands a particular Advisor - * or Advice types + * automatically recognized by an {@code AdvisorAdapterRegistry} implementation. + * @param adapter AdvisorAdapter that understands particular Advisor or Advice types */ void registerAdvisorAdapter(AdvisorAdapter adapter); diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/SimpleAsyncUncaughtExceptionHandler.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/SimpleAsyncUncaughtExceptionHandler.java index dffba79e80..e77f84b435 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/SimpleAsyncUncaughtExceptionHandler.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/SimpleAsyncUncaughtExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -29,13 +29,13 @@ import org.apache.commons.logging.LogFactory; */ public class SimpleAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler { - private final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class); + private static final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class); + @Override public void handleUncaughtException(Throwable ex, Method method, Object... params) { if (logger.isErrorEnabled()) { - logger.error(String.format("Unexpected error occurred invoking async " + - "method '%s'.", method), ex); + logger.error("Unexpected error occurred invoking async method: " + method, ex); } } diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java index 67c4d82770..6d62634237 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -47,11 +47,11 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests { private final DefaultJCacheOperationSource source = new DefaultJCacheOperationSource(); - private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); + private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @Before - public void setUp() { + public void setup() { source.setCacheResolver(defaultCacheResolver); source.setExceptionCacheResolver(defaultExceptionCacheResolver); source.setKeyGenerator(defaultKeyGenerator); diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java index de53ffa585..11864d2425 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -37,12 +37,12 @@ public class CachingConfigurerSupport implements CachingConfigurer { } @Override - public KeyGenerator keyGenerator() { + public CacheResolver cacheResolver() { return null; } @Override - public CacheResolver cacheResolver() { + public KeyGenerator keyGenerator() { return null; } diff --git a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java index 6a0745e5b5..48871cadef 100644 --- a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -110,21 +110,21 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser */ private static void parseCacheResolution(Element element, BeanDefinition def, boolean setBoth) { String name = element.getAttribute("cache-resolver"); - if (StringUtils.hasText(name)) { + boolean hasText = StringUtils.hasText(name); + if (hasText) { def.getPropertyValues().add("cacheResolver", new RuntimeBeanReference(name.trim())); } - if (!StringUtils.hasText(name) || setBoth) { + if (!hasText || setBoth) { def.getPropertyValues().add("cacheManager", new RuntimeBeanReference(CacheNamespaceHandler.extractCacheManager(element))); } } - private static BeanDefinition parseErrorHandler(Element element, BeanDefinition def) { + private static void parseErrorHandler(Element element, BeanDefinition def) { String name = element.getAttribute("error-handler"); if (StringUtils.hasText(name)) { def.getPropertyValues().add("errorHandler", new RuntimeBeanReference(name.trim())); } - return def; } @@ -173,12 +173,12 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser } /** - * Registers a + * Registers a cache aspect. *

-		 * 
-		 *   
-		 *   
-		 * 
+		 * <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
+		 *   <property name="cacheManager" ref="cacheManager"/>
+		 *   <property name="keyGenerator" ref="keyGenerator"/>
+		 * </bean>
 		 * 
*/ private static void registerCacheAspect(Element element, ParserContext parserContext) { 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 966e8fa5ba..90ecccb814 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 @@ -207,8 +207,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } catch (NoUniqueBeanDefinitionException ex) { throw new IllegalStateException("No CacheResolver specified, and no unique bean of type " + - "CacheManager found. Mark one as primary (or give it the name 'cacheManager') or " + - "declare a specific CacheManager to use, that serves as the default one."); + "CacheManager found. Mark one as primary or declare a specific CacheManager to use."); } catch (NoSuchBeanDefinitionException ex) { throw new IllegalStateException("No CacheResolver specified, and no bean of type CacheManager found. " + @@ -651,6 +650,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } + /** + * A {@link CacheOperationInvocationContext} context for a {@link CacheOperation}. + */ protected class CacheOperationContext implements CacheOperationInvocationContext { private final CacheOperationMetadata metadata; diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index e1e3a7f81d..28935f536e 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -619,9 +619,9 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen return null; } - @SuppressWarnings("unchecked") + @SuppressWarnings({"rawtypes", "unchecked"}) private Reference[] createReferenceArray(int size) { - return (Reference[]) Array.newInstance(Reference.class, size); + return new Reference[size]; } private int getIndex(int hash, Reference[] references) { @@ -756,8 +756,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Execute the task. - * @param ref the found reference or {@code null} - * @param entry the found entry or {@code null} + * @param ref the found reference (or {@code null}) + * @param entry the found entry (or {@code null}) * @param entries access to the underlying entries * @return the result of the task * @see #execute(Reference, Entry) @@ -768,8 +768,8 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Convenience method that can be used for tasks that do not need access to {@link Entries}. - * @param ref the found reference or {@code null} - * @param entry the found entry or {@code null} + * @param ref the found reference (or {@code null}) + * @param entry the found entry (or {@code null}) * @return the result of the task * @see #execute(Reference, Entry, Entries) */ diff --git a/spring-core/src/test/java/org/springframework/core/annotation/OrderUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/OrderUtilsTests.java index 9b386aa2ad..83fc8c82fc 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/OrderUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/OrderUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 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. @@ -23,41 +23,48 @@ import org.junit.Test; import static org.junit.Assert.*; /** - * * @author Stephane Nicoll + * @author Juergen Hoeller */ public class OrderUtilsTests { @Test public void getSimpleOrder() { assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null)); + assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null)); } @Test public void getPriorityOrder() { assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null)); + assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null)); } @Test public void getOrderWithBoth() { assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null)); + assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null)); } @Test public void getDefaultOrder() { assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33)); + assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33)); } @Test public void getPriorityValueNoAnnotation() { assertNull(OrderUtils.getPriority(SimpleOrder.class)); + assertNull(OrderUtils.getPriority(SimpleOrder.class)); } @Test public void getPriorityValue() { assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class)); + assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class)); } + @Order(50) private static class SimpleOrder {}