diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java index 3a1a8575ee5..71ccb63a53b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.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. @@ -16,8 +16,8 @@ package org.springframework.aop.aspectj.annotation; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -87,8 +87,8 @@ public class BeanFactoryAspectJAdvisorsBuilder { synchronized (this) { aspectNames = this.aspectBeanNames; if (aspectNames == null) { - List advisors = new LinkedList<>(); - aspectNames = new LinkedList<>(); + List advisors = new ArrayList<>(); + aspectNames = new ArrayList<>(); String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( this.beanFactory, Object.class, true, false); for (String beanName : beanNames) { @@ -138,7 +138,7 @@ public class BeanFactoryAspectJAdvisorsBuilder { if (aspectNames.isEmpty()) { return Collections.emptyList(); } - List advisors = new LinkedList<>(); + List advisors = new ArrayList<>(); for (String aspectName : aspectNames) { List cachedAdvisors = this.advisorsCache.get(aspectName); if (cachedAdvisors != null) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 1b4ea1ed7c2..1d74071687e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -20,8 +20,8 @@ import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Comparator; -import java.util.LinkedList; import java.util.List; import org.aopalliance.aop.Advice; @@ -121,7 +121,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto MetadataAwareAspectInstanceFactory lazySingletonAspectInstanceFactory = new LazySingletonAspectInstanceFactoryDecorator(aspectInstanceFactory); - List advisors = new LinkedList<>(); + List advisors = new ArrayList<>(); for (Method method : getAdvisorMethods(aspectClass)) { Advisor advisor = getAdvisor(method, lazySingletonAspectInstanceFactory, advisors.size(), aspectName); if (advisor != null) { @@ -147,7 +147,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto } private List getAdvisorMethods(Class aspectClass) { - final List methods = new LinkedList<>(); + final List methods = new ArrayList<>(); ReflectionUtils.doWithMethods(aspectClass, method -> { // Exclude pointcuts if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java index a0852f23dfa..489b46be58e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.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. @@ -34,7 +34,7 @@ public class ProxyCreatorSupport extends AdvisedSupport { private AopProxyFactory aopProxyFactory; - private List listeners = new LinkedList<>(); + private final List listeners = new LinkedList<>(); /** Set to true when the first AOP proxy has been created */ private boolean active = false; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java index d69c6b2ff52..e18aac61531 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.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. @@ -16,7 +16,7 @@ package org.springframework.aop.framework.autoproxy; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; @@ -78,10 +78,10 @@ public class BeanFactoryAdvisorRetrievalHelper { } } if (advisorNames.length == 0) { - return new LinkedList<>(); + return new ArrayList<>(); } - List advisors = new LinkedList<>(); + List advisors = new ArrayList<>(); for (String name : advisorNames) { if (isEligibleBean(name)) { if (this.beanFactory.isCurrentlyInCreation(name)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java index d7e3665f1b6..83358da1594 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java @@ -20,8 +20,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; +import java.util.ArrayList; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -305,7 +305,7 @@ public abstract class AopUtils { if (candidateAdvisors.isEmpty()) { return candidateAdvisors; } - List eligibleAdvisors = new LinkedList<>(); + List eligibleAdvisors = new ArrayList<>(); for (Advisor candidate : candidateAdvisors) { if (candidate instanceof IntroductionAdvisor && canApply(candidate, clazz)) { eligibleAdvisors.add(candidate); diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index 2b2b7d85ee6..4c450954fa0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.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. @@ -18,8 +18,8 @@ package org.springframework.aop.support; import java.io.Serializable; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import org.springframework.lang.Nullable; @@ -38,7 +38,7 @@ import org.springframework.util.PatternMatchUtils; @SuppressWarnings("serial") public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut implements Serializable { - private List mappedNames = new LinkedList<>(); + private List mappedNames = new ArrayList<>(); /** @@ -55,11 +55,8 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme * Matching will be the union of all these; if any match, * the pointcut matches. */ - public void setMappedNames(@Nullable String... mappedNames) { - this.mappedNames = new LinkedList<>(); - if (mappedNames != null) { - this.mappedNames.addAll(Arrays.asList(mappedNames)); - } + public void setMappedNames(String... mappedNames) { + this.mappedNames = new ArrayList<>(Arrays.asList(mappedNames)); } /** diff --git a/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java index 2bfa7e6a039..e7728a2d307 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/NameMatchMethodPointcutTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,11 +41,12 @@ public class NameMatchMethodPointcutTests { protected SerializableNopInterceptor nop; + /** * Create an empty pointcut, populating instance variables. */ @Before - public void setUp() { + public void setup() { ProxyFactory pf = new ProxyFactory(new SerializablePerson()); nop = new SerializableNopInterceptor(); pc = new NameMatchMethodPointcut(); @@ -53,6 +54,7 @@ public class NameMatchMethodPointcutTests { proxied = (Person) pf.getProxy(); } + @Test public void testMatchingOnly() { // Can't do exact matching through isMatch @@ -94,7 +96,7 @@ public class NameMatchMethodPointcutTests { @Test public void testSets() throws Throwable { - pc.setMappedNames(new String[] { "set*", "echo" }); + pc.setMappedNames("set*", "echo"); assertEquals(0, nop.getCount()); proxied.getName(); proxied.setName(""); @@ -116,7 +118,7 @@ public class NameMatchMethodPointcutTests { } @Test - public void testEqualsAndHashCode() throws Exception { + public void testEqualsAndHashCode() { NameMatchMethodPointcut pc1 = new NameMatchMethodPointcut(); NameMatchMethodPointcut pc2 = new NameMatchMethodPointcut(); diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java index 71395c9328b..3f88f663457 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java @@ -16,8 +16,8 @@ package org.springframework.beans; +import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -110,7 +110,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl } catch (PropertyAccessException ex) { if (propertyAccessExceptions == null) { - propertyAccessExceptions = new LinkedList<>(); + propertyAccessExceptions = new ArrayList<>(); } propertyAccessExceptions.add(ex); } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index 4f2528d6019..c6ab36971f8 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -27,12 +27,12 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.file.Path; import java.time.ZoneId; +import java.util.ArrayList; import java.util.Collection; import java.util.Currency; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -318,7 +318,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { // Check property-specific editor first. PropertyEditor editor = getCustomEditor(propertyPath, requiredType); if (editor == null) { - List strippedPaths = new LinkedList<>(); + List strippedPaths = new ArrayList<>(); addStrippedPropertyPaths(strippedPaths, "", propertyPath); for (Iterator it = strippedPaths.iterator(); it.hasNext() && editor == null;) { String strippedPath = it.next(); @@ -438,7 +438,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { if (this.customEditorsForPath != null) { CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName); if (editorHolder == null) { - List strippedPaths = new LinkedList<>(); + List strippedPaths = new ArrayList<>(); addStrippedPropertyPaths(strippedPaths, "", propertyName); for (Iterator it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) { String strippedName = it.next(); @@ -517,7 +517,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * Holder for a registered custom editor with property name. * Keeps the PropertyEditor itself plus the type it was registered for. */ - private static class CustomEditorHolder { + private static final class CustomEditorHolder { private final PropertyEditor propertyEditor; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java index cb968c736b9..ccf5a429fa5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java @@ -18,7 +18,7 @@ package org.springframework.beans.factory; import java.io.PrintStream; import java.io.PrintWriter; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.beans.FatalBeanException; @@ -135,7 +135,7 @@ public class BeanCreationException extends FatalBeanException { */ public void addRelatedCause(Throwable ex) { if (this.relatedCauses == null) { - this.relatedCauses = new LinkedList<>(); + this.relatedCauses = new ArrayList<>(); } this.relatedCauses.add(ex); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index c2a44deb427..c41a0972ff6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -245,10 +244,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean ReflectionUtils.doWithMethods(beanClass, method -> { Lookup lookup = method.getAnnotation(Lookup.class); if (lookup != null) { - Assert.state(beanFactory != null, "No BeanFactory available"); + Assert.state(this.beanFactory != null, "No BeanFactory available"); LookupOverride override = new LookupOverride(method, lookup.value()); try { - RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName); + RootBeanDefinition mbd = (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(beanName); mbd.getMethodOverrides().addOverride(override); } catch (NoSuchBeanDefinitionException ex) { @@ -424,11 +423,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } private InjectionMetadata buildAutowiringMetadata(final Class clazz) { - LinkedList elements = new LinkedList<>(); + List elements = new ArrayList<>(); Class targetClass = clazz; do { - final LinkedList currElements = new LinkedList<>(); + final List currElements = new ArrayList<>(); ReflectionUtils.doWithLocalFields(targetClass, field -> { AnnotationAttributes ann = findAutowiredAnnotation(field); @@ -541,7 +540,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean private Object resolvedCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) { if (cachedArgument instanceof DependencyDescriptor) { DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument; - Assert.state(beanFactory != null, "No BeanFactory available"); + Assert.state(this.beanFactory != null, "No BeanFactory available"); return this.beanFactory.resolveDependency(descriptor, beanName, null, null); } else { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index 422e61f57a5..ead10fac887 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -23,9 +23,10 @@ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -196,23 +197,23 @@ public class InitDestroyAnnotationBeanPostProcessor private LifecycleMetadata buildLifecycleMetadata(final Class clazz) { final boolean debug = logger.isDebugEnabled(); - LinkedList initMethods = new LinkedList<>(); - LinkedList destroyMethods = new LinkedList<>(); + List initMethods = new ArrayList<>(); + List destroyMethods = new ArrayList<>(); Class targetClass = clazz; do { - final LinkedList currInitMethods = new LinkedList<>(); - final LinkedList currDestroyMethods = new LinkedList<>(); + final List currInitMethods = new ArrayList<>(); + final List currDestroyMethods = new ArrayList<>(); ReflectionUtils.doWithLocalMethods(targetClass, method -> { - if (initAnnotationType != null && method.isAnnotationPresent(initAnnotationType)) { + if (this.initAnnotationType != null && method.isAnnotationPresent(this.initAnnotationType)) { LifecycleElement element = new LifecycleElement(method); currInitMethods.add(element); if (debug) { logger.debug("Found init method on class [" + clazz.getName() + "]: " + method); } } - if (destroyAnnotationType != null && method.isAnnotationPresent(destroyAnnotationType)) { + if (this.destroyAnnotationType != null && method.isAnnotationPresent(this.destroyAnnotationType)) { currDestroyMethods.add(new LifecycleElement(method)); if (debug) { logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index 43189476678..db4ae1e6c12 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.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. @@ -16,10 +16,10 @@ package org.springframework.beans.factory.config; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -45,7 +45,7 @@ public class ConstructorArgumentValues { private final Map indexedArgumentValues = new LinkedHashMap<>(0); - private final List genericArgumentValues = new LinkedList<>(); + private final List genericArgumentValues = new ArrayList<>(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java index 29d45dd4f54..9d6ff690a4c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java @@ -16,7 +16,7 @@ package org.springframework.beans.factory.parsing; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.lang.Nullable; @@ -38,7 +38,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { @Nullable private final Object source; - private final List nestedComponents = new LinkedList<>(); + private final List nestedComponents = new ArrayList<>(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index d9e231043ee..83447da6757 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -30,7 +30,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -1495,7 +1494,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #isExcludedFromDependencyCheck */ protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) { - List pds = new LinkedList<>(Arrays.asList(bw.getPropertyDescriptors())); + List pds = new ArrayList<>(Arrays.asList(bw.getPropertyDescriptors())); pds.removeIf(this::isExcludedFromDependencyCheck); return pds.toArray(new PropertyDescriptor[0]); } diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java index 633eeea655e..50be8384761 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -113,7 +112,7 @@ public class FreeMarkerConfigurationFactory { * @see #setTemplateLoaderPath */ public void setConfigLocation(Resource resource) { - configLocation = resource; + this.configLocation = resource; } /** @@ -285,7 +284,7 @@ public class FreeMarkerConfigurationFactory { config.setDefaultEncoding(this.defaultEncoding); } - List templateLoaders = new LinkedList<>(this.templateLoaders); + List templateLoaders = new ArrayList<>(this.templateLoaders); // Register template loaders that are supposed to kick in early. if (this.preTemplateLoaders != null) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index 6e5df87641a..beace7303d7 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.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. @@ -28,10 +28,11 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -47,7 +48,6 @@ import javax.xml.ws.WebServiceRef; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; @@ -300,18 +300,18 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } @Override - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { return null; } @Override - public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { + public boolean postProcessAfterInstantiation(Object bean, String beanName) { return true; } @Override public PropertyValues postProcessPropertyValues( - PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { + PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) { InjectionMetadata metadata = findResourceMetadata(beanName, bean.getClass(), pvs); try { @@ -345,12 +345,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } private InjectionMetadata buildResourceMetadata(final Class clazz) { - LinkedList elements = new LinkedList<>(); + List elements = new ArrayList<>(); Class targetClass = clazz; do { - final LinkedList currElements = - new LinkedList<>(); + final List currElements = new ArrayList<>(); ReflectionUtils.doWithLocalFields(targetClass, field -> { if (webServiceRefClass != null && field.isAnnotationPresent(webServiceRefClass)) { @@ -369,7 +368,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean if (Modifier.isStatic(field.getModifiers())) { throw new IllegalStateException("@Resource annotation is not supported on static fields"); } - if (!ignoredResourceTypes.contains(field.getType().getName())) { + if (!this.ignoredResourceTypes.contains(field.getType().getName())) { currElements.add(new ResourceElement(field, field, null)); } } @@ -409,7 +408,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean if (paramTypes.length != 1) { throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method); } - if (!ignoredResourceTypes.contains(paramTypes[0].getName())) { + if (!this.ignoredResourceTypes.contains(paramTypes[0].getName())) { PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); currElements.add(new ResourceElement(method, bridgedMethod, pd)); } @@ -468,9 +467,11 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean * @param element the descriptor for the annotated field/method * @param requestingBeanName the name of the requesting bean * @return the resource object (never {@code null}) - * @throws BeansException if we failed to obtain the target resource + * @throws NoSuchBeanDefinitionException if no corresponding target resource found */ - protected Object getResource(LookupElement element, @Nullable String requestingBeanName) throws BeansException { + protected Object getResource(LookupElement element, @Nullable String requestingBeanName) + throws NoSuchBeanDefinitionException { + if (StringUtils.hasLength(element.mappedName)) { return this.jndiFactory.getBean(element.mappedName, element.lookupType); } @@ -491,10 +492,10 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean * @param element the descriptor for the annotated field/method * @param requestingBeanName the name of the requesting bean * @return the resource object (never {@code null}) - * @throws BeansException if we failed to obtain the target resource + * @throws NoSuchBeanDefinitionException if no corresponding target resource found */ protected Object autowireResource(BeanFactory factory, LookupElement element, @Nullable String requestingBeanName) - throws BeansException { + throws NoSuchBeanDefinitionException { Object resource; Set autowiredBeanNames; diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index 477d1a86a1d..73fa12f2942 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.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. @@ -16,9 +16,10 @@ package org.springframework.context.event; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; -import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -213,7 +214,7 @@ public abstract class AbstractApplicationEventMulticaster private Collection> retrieveApplicationListeners( ResolvableType eventType, @Nullable Class sourceType, @Nullable ListenerRetriever retriever) { - LinkedList> allListeners = new LinkedList<>(); + List> allListeners = new ArrayList<>(); Set> listeners; Set listenerBeans; synchronized (this.retrievalMutex) { @@ -368,10 +369,9 @@ public abstract class AbstractApplicationEventMulticaster } public Collection> getApplicationListeners() { - LinkedList> allListeners = new LinkedList<>(); - for (ApplicationListener listener : this.applicationListeners) { - allListeners.add(listener); - } + List> allListeners = new ArrayList<>( + this.applicationListeners.size() + this.applicationListenerBeans.size()); + allListeners.addAll(this.applicationListeners); if (!this.applicationListenerBeans.isEmpty()) { BeanFactory beanFactory = getBeanFactory(); for (String listenerBeanName : this.applicationListenerBeans) { diff --git a/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java b/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java index a316814ed2c..bf0be938d23 100644 --- a/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java +++ b/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java @@ -18,10 +18,8 @@ package org.springframework.context.support; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -48,7 +46,7 @@ import org.springframework.lang.Nullable; * @author Juergen Hoeller * @since 4.0 */ -class PostProcessorRegistrationDelegate { +final class PostProcessorRegistrationDelegate { public static void invokeBeanFactoryPostProcessors( ConfigurableListableBeanFactory beanFactory, List beanFactoryPostProcessors) { @@ -58,8 +56,8 @@ class PostProcessorRegistrationDelegate { if (beanFactory instanceof BeanDefinitionRegistry) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; - List regularPostProcessors = new LinkedList<>(); - List registryProcessors = new LinkedList<>(); + List regularPostProcessors = new ArrayList<>(); + List registryProcessors = new ArrayList<>(); for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) { if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) { @@ -302,7 +300,7 @@ class PostProcessorRegistrationDelegate { * BeanPostProcessor instantiation, i.e. when a bean is not eligible for * getting processed by all BeanPostProcessors. */ - private static class BeanPostProcessorChecker implements BeanPostProcessor { + private static final class BeanPostProcessorChecker implements BeanPostProcessor { private static final Log logger = LogFactory.getLog(BeanPostProcessorChecker.class); diff --git a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java index 9a50606e0cc..246749650ed 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java @@ -17,8 +17,8 @@ package org.springframework.expression.common; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Deque; -import java.util.LinkedList; import java.util.List; import org.springframework.expression.Expression; @@ -87,7 +87,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser * @throws ParseException when the expressions cannot be parsed */ private Expression[] parseExpressions(String expressionString, ParserContext context) throws ParseException { - List expressions = new LinkedList<>(); + List expressions = new ArrayList<>(); String prefix = context.getExpressionPrefix(); String suffix = context.getExpressionSuffix(); int startIdx = 0; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index 42f2e3d3367..28f4cfd6b6b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -20,7 +20,6 @@ import java.util.ArrayDeque; import java.util.Collections; import java.util.Deque; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -65,7 +64,7 @@ public class ExpressionState { private Deque contextObjects; @Nullable - private LinkedList variableScopes; + private Deque variableScopes; // When entering a new scope there is a new base object which should be used // for '#this' references (or to act as a target for unqualified references). @@ -215,7 +214,7 @@ public class ExpressionState { private Deque initVariableScopes() { if (this.variableScopes == null) { - this.variableScopes = new LinkedList<>(); + this.variableScopes = new ArrayDeque<>(); // top-level empty variable scope this.variableScopes.add(new VariableScope()); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java index f80a82696d6..9b7ac3d4885 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.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. @@ -17,7 +17,6 @@ package org.springframework.expression.spel.ast; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import org.springframework.expression.PropertyAccessor; @@ -68,7 +67,7 @@ public abstract class AstUtils { } } } - List resolvers = new LinkedList<>(); + List resolvers = new ArrayList<>(specificAccessors.size() + generalAccessors.size()); resolvers.addAll(specificAccessors); resolvers.addAll(generalAccessors); return resolvers; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java index 9b2480d75b5..73568fc83e2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java @@ -20,7 +20,6 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.Deque; -import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; @@ -456,7 +455,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } /** - * Used for consuming arguments for either a method or a constructor call + * Used for consuming arguments for either a method or a constructor call. */ private void consumeArguments(List accumulatedArguments) { Token t = peekToken(); @@ -724,7 +723,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { - LinkedList qualifiedIdPieces = new LinkedList<>(); + Deque qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index 8444672bcdc..50e471bb0dc 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -22,7 +22,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.Statement; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; @@ -339,7 +339,7 @@ public abstract class ScriptUtils { /** * Does the provided SQL script contain the specified delimiter? * @param script the SQL script - * @param delim String delimiting each statement - typically a ';' character + * @param delim the string delimiting each statement - typically a ';' character */ public static boolean containsSqlScriptDelimiters(String script, String delim) { boolean inLiteral = false; @@ -460,7 +460,7 @@ public abstract class ScriptUtils { separator = FALLBACK_STATEMENT_SEPARATOR; } - List statements = new LinkedList<>(); + List statements = new ArrayList<>(); splitSqlScript(resource, script, separator, commentPrefix, blockCommentStartDelimiter, blockCommentEndDelimiter, statements); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/BatchSqlUpdate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/BatchSqlUpdate.java index c51c7c58f78..58b76ec2cef 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/BatchSqlUpdate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/BatchSqlUpdate.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. @@ -18,9 +18,10 @@ package org.springframework.jdbc.object; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import javax.sql.DataSource; @@ -55,7 +56,7 @@ public class BatchSqlUpdate extends SqlUpdate { private boolean trackRowsAffected = true; - private final LinkedList parameterQueue = new LinkedList<>(); + private final Deque parameterQueue = new ArrayDeque<>(); private final List rowsAffected = new ArrayList<>(); @@ -72,8 +73,8 @@ public class BatchSqlUpdate extends SqlUpdate { /** * Construct an update object with a given DataSource and SQL. - * @param ds DataSource to use to obtain connections - * @param sql SQL statement to execute + * @param ds the DataSource to use to obtain connections + * @param sql the SQL statement to execute */ public BatchSqlUpdate(DataSource ds, String sql) { super(ds, sql); @@ -82,9 +83,9 @@ public class BatchSqlUpdate extends SqlUpdate { /** * Construct an update object with a given DataSource, SQL * and anonymous parameters. - * @param ds DataSource to use to obtain connections - * @param sql SQL statement to execute - * @param types SQL types of the parameters, as defined in the + * @param ds the DataSource to use to obtain connections + * @param sql the SQL statement to execute + * @param types the SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @see java.sql.Types */ @@ -96,9 +97,9 @@ public class BatchSqlUpdate extends SqlUpdate { * Construct an update object with a given DataSource, SQL, * anonymous parameters and specifying the maximum number of rows * that may be affected. - * @param ds DataSource to use to obtain connections - * @param sql SQL statement to execute - * @param types SQL types of the parameters, as defined in the + * @param ds the DataSource to use to obtain connections + * @param sql the SQL statement to execute + * @param types the SQL types of the parameters, as defined in the * {@code java.sql.Types} class * @param batchSize the number of statements that will trigger * an automatic intermediate flush diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index e3f2af72452..84327da32e0 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.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. @@ -22,7 +22,9 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; @@ -35,7 +37,6 @@ import javax.persistence.PersistenceUnit; import javax.persistence.SynchronizationType; import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; @@ -311,12 +312,12 @@ public class PersistenceAnnotationBeanPostProcessor } public void setOrder(int order) { - this.order = order; + this.order = order; } @Override public int getOrder() { - return this.order; + return this.order; } @Override @@ -334,18 +335,18 @@ public class PersistenceAnnotationBeanPostProcessor } @Override - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { return null; } @Override - public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { + public boolean postProcessAfterInstantiation(Object bean, String beanName) { return true; } @Override public PropertyValues postProcessPropertyValues( - PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { + PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) { InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass(), pvs); try { @@ -358,17 +359,17 @@ public class PersistenceAnnotationBeanPostProcessor } @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + public Object postProcessBeforeInitialization(Object bean, String beanName) { return bean; } @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + public Object postProcessAfterInitialization(Object bean, String beanName) { return bean; } @Override - public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException { + public void postProcessBeforeDestruction(Object bean, String beanName) { EntityManager emToClose = this.extendedEntityManagersToClose.remove(bean); EntityManagerFactoryUtils.closeEntityManager(emToClose); } @@ -400,7 +401,7 @@ public class PersistenceAnnotationBeanPostProcessor } private InjectionMetadata buildPersistenceMetadata(final Class clazz) { - LinkedList elements = new LinkedList<>(); + List elements = new ArrayList<>(); Class targetClass = clazz; do { diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 7bf28fd4309..fa76e1a022f 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -18,7 +18,6 @@ package org.springframework.web.accept; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -46,7 +45,7 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten private final MultiValueMap fileExtensions = new LinkedMultiValueMap<>(); - private final List allFileExtensions = new LinkedList<>(); + private final List allFileExtensions = new ArrayList<>(); /**