Browse Source

Consistent use of Collection.toArray with zero-sized array argument

Includes consistent use of ClassUtils.toClassArray (as non-null variant)

Issue: SPR-16523
pull/1699/head
Juergen Hoeller 8 years ago
parent
commit
a5cbf5fe24
  1. 6
      spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java
  2. 6
      spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
  3. 4
      spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java
  4. 2
      spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
  5. 4
      spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java
  6. 2
      spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java
  7. 5
      spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java
  8. 4
      spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java
  9. 4
      spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java
  10. 4
      spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java
  11. 2
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  12. 6
      spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java
  13. 4
      spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java
  14. 15
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  15. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
  16. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  17. 4
      spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
  18. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java
  19. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java
  20. 9
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java
  21. 4
      spring-context-support/src/main/java/org/springframework/mail/MailSendException.java
  22. 6
      spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java
  23. 7
      spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java
  24. 4
      spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java
  25. 3
      spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
  26. 4
      spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java
  27. 6
      spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java
  28. 4
      spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java
  29. 9
      spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java
  30. 4
      spring-core/src/main/java/org/springframework/core/convert/Property.java
  31. 6
      spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
  32. 4
      spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java
  33. 5
      spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java
  34. 24
      spring-core/src/main/java/org/springframework/util/ClassUtils.java
  35. 6
      spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
  36. 4
      spring-core/src/main/java/org/springframework/util/StopWatch.java
  37. 5
      spring-core/src/main/java/org/springframework/util/StringUtils.java
  38. 6
      spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
  39. 47
      spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
  40. 2
      spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java
  41. 6
      spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java
  42. 7
      spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
  43. 4
      spring-jms/src/main/java/org/springframework/jms/connection/ChainedExceptionListener.java
  44. 9
      spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java
  45. 15
      spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java
  46. 5
      spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java
  47. 4
      spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java
  48. 4
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
  49. 4
      spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java
  50. 2
      spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java
  51. 4
      spring-test/src/main/java/org/springframework/test/context/TestContextManager.java
  52. 4
      spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java
  53. 3
      spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
  54. 5
      spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java
  55. 5
      spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java
  56. 4
      spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java
  57. 2
      spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
  58. 6
      spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
  59. 4
      spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java
  60. 4
      spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java
  61. 2
      spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java
  62. 6
      spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java
  63. 10
      spring-web/src/main/java/org/springframework/web/server/handler/FilteringWebHandler.java
  64. 2
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java
  65. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java
  66. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java
  67. 11
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
  68. 29
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
  69. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
  70. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java
  71. 2
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java
  72. 11
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java

6
spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -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.
@ -253,8 +253,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { @@ -253,8 +253,8 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
List<BeanReference> beanRefs, ParserContext parserContext) {
BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]);
BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[0]);
BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[0]);
Object source = parserContext.extractSource(aspectElement);
return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
}

6
spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

@ -1,5 +1,5 @@ @@ -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.
@ -228,7 +228,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @@ -228,7 +228,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
@Override
public Class<?>[] getProxiedInterfaces() {
return this.interfaces.toArray(new Class<?>[this.interfaces.size()]);
return ClassUtils.toClassArray(this.interfaces);
}
@Override
@ -372,7 +372,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @@ -372,7 +372,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* Bring the array up to date with the list.
*/
protected final void updateAdvisorArray() {
this.advisorArray = this.advisors.toArray(new Advisor[this.advisors.size()]);
this.advisorArray = this.advisors.toArray(new Advisor[0]);
}
/**

4
spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java

@ -1,5 +1,5 @@ @@ -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.
@ -90,7 +90,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se @@ -90,7 +90,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
if (interceptors.isEmpty()) {
throw new UnknownAdviceTypeException(advisor.getAdvice());
}
return interceptors.toArray(new MethodInterceptor[interceptors.size()]);
return interceptors.toArray(new MethodInterceptor[0]);
}
@Override

2
spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

@ -554,7 +554,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport @@ -554,7 +554,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
advisors.add(this.advisorAdapterRegistry.wrap(next));
}
}
return advisors.toArray(new Advisor[advisors.size()]);
return advisors.toArray(new Advisor[0]);
}
/**

4
spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java

@ -1,5 +1,5 @@ @@ -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.
@ -105,7 +105,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil @@ -105,7 +105,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
@Override
public Class<?>[] getInterfaces() {
return this.interfaces.toArray(new Class<?>[this.interfaces.size()]);
return ClassUtils.toClassArray(this.interfaces);
}
@Override

2
spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java

@ -61,7 +61,7 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable { @@ -61,7 +61,7 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
@Override
public Class<?>[] getInterfaces() {
return this.publishedInterfaces.toArray(new Class<?>[this.publishedInterfaces.size()]);
return ClassUtils.toClassArray(this.publishedInterfaces);
}
/**

5
spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java

@ -1,5 +1,5 @@ @@ -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.
@ -118,8 +118,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl @@ -118,8 +118,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
// If we encountered individual exceptions, throw the composite exception.
if (propertyAccessExceptions != null) {
PropertyAccessException[] paeArray =
propertyAccessExceptions.toArray(new PropertyAccessException[propertyAccessExceptions.size()]);
PropertyAccessException[] paeArray = propertyAccessExceptions.toArray(new PropertyAccessException[0]);
throw new PropertyBatchUpdateException(paeArray);
}
}

4
spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

@ -1,5 +1,5 @@ @@ -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.
@ -220,7 +220,7 @@ class ExtendedBeanInfo implements BeanInfo { @@ -220,7 +220,7 @@ class ExtendedBeanInfo implements BeanInfo {
*/
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
return this.propertyDescriptors.toArray(new PropertyDescriptor[this.propertyDescriptors.size()]);
return this.propertyDescriptors.toArray(new PropertyDescriptor[0]);
}
@Override

4
spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java

@ -1,5 +1,5 @@ @@ -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.
@ -246,7 +246,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable { @@ -246,7 +246,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
@Override
public PropertyValue[] getPropertyValues() {
return this.propertyValueList.toArray(new PropertyValue[this.propertyValueList.size()]);
return this.propertyValueList.toArray(new PropertyValue[0]);
}
@Override

4
spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java

@ -1,5 +1,5 @@ @@ -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.
@ -149,7 +149,7 @@ public class BeanCreationException extends FatalBeanException { @@ -149,7 +149,7 @@ public class BeanCreationException extends FatalBeanException {
if (this.relatedCauses == null) {
return null;
}
return this.relatedCauses.toArray(new Throwable[this.relatedCauses.size()]);
return this.relatedCauses.toArray(new Throwable[0]);
}

2
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -342,7 +342,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean @@ -342,7 +342,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
"default constructor to fall back to: " + candidates.get(0));
}
}
candidateConstructors = candidates.toArray(new Constructor<?>[candidates.size()]);
candidateConstructors = candidates.toArray(new Constructor<?>[0]);
}
else if (rawCandidates.length == 1 && rawCandidates[0].getParameterCount() > 0) {
candidateConstructors = new Constructor<?>[] {rawCandidates[0]};

6
spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java

@ -1,5 +1,5 @@ @@ -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.
@ -83,8 +83,8 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com @@ -83,8 +83,8 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com
references.add((BeanReference) value);
}
}
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[innerBeans.size()]);
this.beanReferences = references.toArray(new BeanReference[references.size()]);
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
this.beanReferences = references.toArray(new BeanReference[0]);
}

4
spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java

@ -1,5 +1,5 @@ @@ -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.
@ -79,7 +79,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { @@ -79,7 +79,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition {
* @return the array of nested components, or an empty array if none
*/
public ComponentDefinition[] getNestedComponents() {
return this.nestedComponents.toArray(new ComponentDefinition[this.nestedComponents.size()]);
return this.nestedComponents.toArray(new ComponentDefinition[0]);
}
}

15
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -1,5 +1,5 @@ @@ -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.
@ -29,7 +29,6 @@ import java.util.ArrayList; @@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
@ -1496,15 +1495,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @@ -1496,15 +1495,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #isExcludedFromDependencyCheck
*/
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
List<PropertyDescriptor> pds =
new LinkedList<>(Arrays.asList(bw.getPropertyDescriptors()));
for (Iterator<PropertyDescriptor> it = pds.iterator(); it.hasNext();) {
PropertyDescriptor pd = it.next();
if (isExcludedFromDependencyCheck(pd)) {
it.remove();
}
}
return pds.toArray(new PropertyDescriptor[pds.size()]);
List<PropertyDescriptor> pds = new LinkedList<>(Arrays.asList(bw.getPropertyDescriptors()));
pds.removeIf(this::isExcludedFromDependencyCheck);
return pds.toArray(new PropertyDescriptor[0]);
}
/**

4
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

@ -1,5 +1,5 @@ @@ -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.
@ -419,7 +419,7 @@ class ConstructorResolver { @@ -419,7 +419,7 @@ class ConstructorResolver {
candidateSet.add(candidate);
}
}
Method[] candidates = candidateSet.toArray(new Method[candidateSet.size()]);
Method[] candidates = candidateSet.toArray(new Method[0]);
AutowireUtils.sortFactoryMethods(candidates);
ConstructorArgumentValues resolvedValues = null;

2
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -1780,7 +1780,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -1780,7 +1780,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
if (targetType != null && targetType != obj.getClass()) {
sources.add(targetType);
}
return sources.toArray(new Object[sources.size()]);
return sources.toArray();
}
@Nullable

4
spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java

@ -1,5 +1,5 @@ @@ -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.
@ -266,7 +266,7 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume @@ -266,7 +266,7 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
ele, ex);
}
}
Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
Resource[] actResArray = actualResources.toArray(new Resource[0]);
getReaderContext().fireImportProcessed(location, actResArray, extractSource(ele));
}

4
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java vendored

@ -1,5 +1,5 @@ @@ -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.
@ -82,7 +82,7 @@ abstract class AbstractJCacheKeyOperation<A extends Annotation> extends Abstract @@ -82,7 +82,7 @@ abstract class AbstractJCacheKeyOperation<A extends Annotation> extends Abstract
}
result.add(keyParameterDetail.toCacheInvocationParameter(values[parameterPosition]));
}
return result.toArray(new CacheInvocationParameter[result.size()]);
return result.toArray(new CacheInvocationParameter[0]);
}

4
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java vendored

@ -1,5 +1,5 @@ @@ -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.
@ -110,7 +110,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp @@ -110,7 +110,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
for (int i = 0; i < this.allParameterDetails.size(); i++) {
result.add(this.allParameterDetails.get(i).toCacheInvocationParameter(values[i]));
}
return result.toArray(new CacheInvocationParameter[result.size()]);
return result.toArray(new CacheInvocationParameter[0]);
}
protected ExceptionTypeFilter createExceptionTypeFilter(

9
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java vendored

@ -104,15 +104,14 @@ class KeyGeneratorAdapter implements KeyGenerator { @@ -104,15 +104,14 @@ class KeyGeneratorAdapter implements KeyGenerator {
parameters.add(value);
}
}
return keyGenerator.generate(context.getTarget(), context.getMethod(),
parameters.toArray(new Object[parameters.size()]));
return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray());
}
@SuppressWarnings("unchecked")
private CacheKeyInvocationContext<?> createCacheKeyInvocationContext(Object target,
JCacheOperation<?> operation, Object[] params) {
private CacheKeyInvocationContext<?> createCacheKeyInvocationContext(
Object target, JCacheOperation<?> operation, Object[] params) {
AbstractJCacheKeyOperation<Annotation> keyCacheOperation = (AbstractJCacheKeyOperation<Annotation>) operation;
return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params);
}

4
spring-context-support/src/main/java/org/springframework/mail/MailSendException.java

@ -1,5 +1,5 @@ @@ -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.
@ -71,7 +71,7 @@ public class MailSendException extends MailException { @@ -71,7 +71,7 @@ public class MailSendException extends MailException {
public MailSendException(@Nullable String msg, @Nullable Throwable cause, Map<Object, Exception> failedMessages) {
super(msg, cause);
this.failedMessages = new LinkedHashMap<>(failedMessages);
this.messageExceptions = failedMessages.values().toArray(new Exception[failedMessages.size()]);
this.messageExceptions = failedMessages.values().toArray(new Exception[0]);
}
/**

6
spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailSenderImpl.java

@ -1,5 +1,5 @@ @@ -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.
@ -318,7 +318,7 @@ public class JavaMailSenderImpl implements JavaMailSender { @@ -318,7 +318,7 @@ public class JavaMailSenderImpl implements JavaMailSender {
simpleMessage.copyTo(message);
mimeMessages.add(message.getMimeMessage());
}
doSend(mimeMessages.toArray(new MimeMessage[mimeMessages.size()]), simpleMessages);
doSend(mimeMessages.toArray(new MimeMessage[0]), simpleMessages);
}
@ -373,7 +373,7 @@ public class JavaMailSenderImpl implements JavaMailSender { @@ -373,7 +373,7 @@ public class JavaMailSenderImpl implements JavaMailSender {
preparator.prepare(mimeMessage);
mimeMessages.add(mimeMessage);
}
send(mimeMessages.toArray(new MimeMessage[mimeMessages.size()]));
send(mimeMessages.toArray(new MimeMessage[0]));
}
catch (MailException ex) {
throw ex;

7
spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java

@ -1,5 +1,5 @@ @@ -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.
@ -390,15 +390,14 @@ public class FreeMarkerConfigurationFactory { @@ -390,15 +390,14 @@ public class FreeMarkerConfigurationFactory {
*/
@Nullable
protected TemplateLoader getAggregateTemplateLoader(List<TemplateLoader> templateLoaders) {
int loaderCount = templateLoaders.size();
switch (loaderCount) {
switch (templateLoaders.size()) {
case 0:
logger.info("No FreeMarker TemplateLoaders specified");
return null;
case 1:
return templateLoaders.get(0);
default:
TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[loaderCount]);
TemplateLoader[] loaders = templateLoaders.toArray(new TemplateLoader[0]);
return new MultiTemplateLoader(loaders);
}
}

4
spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java

@ -1,5 +1,5 @@ @@ -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.
@ -337,7 +337,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme @@ -337,7 +337,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
resolvedArgs.add(arg);
}
}
return resolvedArgs.toArray(new Object[resolvedArgs.size()]);
return resolvedArgs.toArray();
}
/**

3
spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

@ -383,8 +383,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo @@ -383,8 +383,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
notificationListeners.add(bean);
});
this.notificationListeners =
notificationListeners.toArray(new NotificationListenerBean[notificationListeners.size()]);
this.notificationListeners = notificationListeners.toArray(new NotificationListenerBean[0]);
}
@Override

4
spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java

@ -1,5 +1,5 @@ @@ -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.
@ -87,7 +87,7 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef @@ -87,7 +87,7 @@ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractRef
ManagedNotification mn = (ManagedNotification) colValue;
result.add(JmxMetadataUtils.convertToModelMBeanNotificationInfo(mn));
}
return result.toArray(new ModelMBeanNotificationInfo[result.size()]);
return result.toArray(new ModelMBeanNotificationInfo[0]);
}
else {
throw new IllegalArgumentException(

6
spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java

@ -1,5 +1,5 @@ @@ -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.
@ -333,7 +333,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean @@ -333,7 +333,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
}
}
return infos.toArray(new ModelMBeanAttributeInfo[infos.size()]);
return infos.toArray(new ModelMBeanAttributeInfo[0]);
}
/**
@ -401,7 +401,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean @@ -401,7 +401,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
}
}
return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
return infos.toArray(new ModelMBeanOperationInfo[0]);
}
/**

4
spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java

@ -1,5 +1,5 @@ @@ -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.
@ -228,7 +228,7 @@ public class MBeanRegistrationSupport { @@ -228,7 +228,7 @@ public class MBeanRegistrationSupport {
*/
protected final ObjectName[] getRegisteredObjectNames() {
synchronized (this.registeredBeans) {
return this.registeredBeans.toArray(new ObjectName[this.registeredBeans.size()]);
return this.registeredBeans.toArray(new ObjectName[0]);
}
}

9
spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

@ -17,9 +17,9 @@ @@ -17,9 +17,9 @@
package org.springframework.validation.beanvalidation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -37,6 +37,7 @@ import org.springframework.context.MessageSourceResolvable; @@ -37,6 +37,7 @@ import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
@ -116,7 +117,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. @@ -116,7 +117,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
}
}
processConstraintViolations(
this.targetValidator.validate(target, groups.toArray(new Class<?>[groups.size()])), errors);
this.targetValidator.validate(target, ClassUtils.toClassArray(groups)), errors);
}
}
@ -241,7 +242,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. @@ -241,7 +242,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
* @see org.springframework.validation.DefaultBindingErrorProcessor#getArgumentsForBindError
*/
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintDescriptor<?> descriptor) {
List<Object> arguments = new LinkedList<>();
List<Object> arguments = new ArrayList<>();
arguments.add(getResolvableField(objectName, field));
// Using a TreeMap for alphabetical ordering of attribute names
Map<String, Object> attributesToExpose = new TreeMap<>();
@ -254,7 +255,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. @@ -254,7 +255,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation.
}
});
arguments.addAll(attributesToExpose.values());
return arguments.toArray(new Object[arguments.size()]);
return arguments.toArray();
}
/**

4
spring-core/src/main/java/org/springframework/core/convert/Property.java

@ -1,5 +1,5 @@ @@ -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.
@ -211,7 +211,7 @@ public final class Property { @@ -211,7 +211,7 @@ public final class Property {
addAnnotationsToMap(annotationMap, getReadMethod());
addAnnotationsToMap(annotationMap, getWriteMethod());
addAnnotationsToMap(annotationMap, getField());
annotations = annotationMap.values().toArray(new Annotation[annotationMap.size()]);
annotations = annotationMap.values().toArray(new Annotation[0]);
annotationCache.put(this, annotations);
}
return annotations;

6
spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

@ -1,5 +1,5 @@ @@ -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.
@ -320,7 +320,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol @@ -320,7 +320,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
if (logger.isDebugEnabled()) {
logger.debug("Resolved classpath location [" + location + "] to resources " + result);
}
return result.toArray(new Resource[result.size()]);
return result.toArray(new Resource[0]);
}
/**
@ -515,7 +515,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol @@ -515,7 +515,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
if (logger.isDebugEnabled()) {
logger.debug("Resolved location pattern [" + locationPattern + "] to resources " + result);
}
return result.toArray(new Resource[result.size()]);
return result.toArray(new Resource[0]);
}
/**

4
spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java

@ -1,5 +1,5 @@ @@ -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.
@ -162,7 +162,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport { @@ -162,7 +162,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
Resource.class.getName() + "]: only location String and Resource object supported");
}
}
super.setValue(merged.toArray(new Resource[merged.size()]));
super.setValue(merged.toArray(new Resource[0]));
}
else {

5
spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java

@ -1,5 +1,5 @@ @@ -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.
@ -78,8 +78,7 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor @@ -78,8 +78,7 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor
@Override
public void visitEnd() {
if (!this.allNestedAttributes.isEmpty()) {
this.attributes.put(this.attributeName,
this.allNestedAttributes.toArray(new AnnotationAttributes[this.allNestedAttributes.size()]));
this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0]));
}
}

24
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -1058,18 +1058,15 @@ public abstract class ClassUtils { @@ -1058,18 +1058,15 @@ public abstract class ClassUtils {
}
/**
* Copy the given Collection into a Class array.
* The Collection must contain Class elements only.
* @param collection the Collection to copy
* @return the Class array ({@code null} if the passed-in
* Collection was {@code null})
*/
@Nullable
public static Class<?>[] toClassArray(@Nullable Collection<Class<?>> collection) {
if (collection == null) {
return null;
}
return collection.toArray(new Class<?>[collection.size()]);
* Copy the given {@code Collection} into a {@code Class} array.
* <p>The {@code Collection} must contain {@code Class} elements only.
* @param collection the {@code Collection} to copy
* @return the {@code Class} array
* @since 3.1
* @see StringUtils#toStringArray
*/
public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
return collection.toArray(new Class<?>[0]);
}
/**
@ -1104,8 +1101,7 @@ public abstract class ClassUtils { @@ -1104,8 +1101,7 @@ public abstract class ClassUtils {
* @return all interfaces that the given object implements as an array
*/
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, @Nullable ClassLoader classLoader) {
Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
return ifcs.toArray(new Class<?>[ifcs.size()]);
return toClassArray(getAllInterfacesForClassAsSet(clazz, classLoader));
}
/**

6
spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

@ -1,5 +1,5 @@ @@ -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.
@ -584,7 +584,7 @@ public abstract class ReflectionUtils { @@ -584,7 +584,7 @@ public abstract class ReflectionUtils {
public static Method[] getAllDeclaredMethods(Class<?> leafClass) {
final List<Method> methods = new ArrayList<>(32);
doWithMethods(leafClass, methods::add);
return methods.toArray(new Method[methods.size()]);
return methods.toArray(new Method[0]);
}
/**
@ -620,7 +620,7 @@ public abstract class ReflectionUtils { @@ -620,7 +620,7 @@ public abstract class ReflectionUtils {
methods.add(method);
}
});
return methods.toArray(new Method[methods.size()]);
return methods.toArray(new Method[0]);
}
/**

4
spring-core/src/main/java/org/springframework/util/StopWatch.java

@ -1,5 +1,5 @@ @@ -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.
@ -229,7 +229,7 @@ public class StopWatch { @@ -229,7 +229,7 @@ public class StopWatch {
if (!this.keepTaskList) {
throw new UnsupportedOperationException("Task info is not being kept!");
}
return this.taskList.toArray(new TaskInfo[this.taskList.size()]);
return this.taskList.toArray(new TaskInfo[0]);
}

5
spring-core/src/main/java/org/springframework/util/StringUtils.java

@ -945,7 +945,7 @@ public abstract class StringUtils { @@ -945,7 +945,7 @@ public abstract class StringUtils {
* @return the {@code String} array
*/
public static String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
return collection.toArray(new String[0]);
}
/**
@ -955,8 +955,7 @@ public abstract class StringUtils { @@ -955,8 +955,7 @@ public abstract class StringUtils {
* @return the {@code String} array
*/
public static String[] toStringArray(Enumeration<String> enumeration) {
List<String> list = Collections.list(enumeration);
return list.toArray(new String[list.size()]);
return toStringArray(Collections.list(enumeration));
}
/**

6
spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

@ -1,5 +1,5 @@ @@ -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,9 +17,9 @@ @@ -17,9 +17,9 @@
package org.springframework.expression.common;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.Deque;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
@ -128,7 +128,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser @@ -128,7 +128,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
}
}
return expressions.toArray(new Expression[expressions.size()]);
return expressions.toArray(new Expression[0]);
}
/**

47
spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java

@ -1,5 +1,5 @@ @@ -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.
@ -365,7 +365,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -365,7 +365,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
}
return new CompoundExpression(toPos(start.getStartPosition(),
nodes.get(nodes.size() - 1).getEndPosition()),
nodes.toArray(new SpelNodeImpl[nodes.size()]));
nodes.toArray(new SpelNodeImpl[0]));
}
// node : ((DOT dottedNode) | (SAFE_NAVI dottedNode) | nonDottedNode)+;
@ -443,7 +443,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -443,7 +443,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
List<SpelNodeImpl> args = new ArrayList<>();
consumeArguments(args);
eatToken(TokenKind.RPAREN);
return args.toArray(new SpelNodeImpl[args.size()]);
return args.toArray(new SpelNodeImpl[0]);
}
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) {
@ -646,36 +646,33 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -646,36 +646,33 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
// ',' - more expressions in this list
// ':' - this is a map!
if (peekToken(TokenKind.RCURLY)) { // list with one item in it
List<SpelNodeImpl> listElements = new ArrayList<>();
listElements.add(firstExpression);
List<SpelNodeImpl> elements = new ArrayList<>();
elements.add(firstExpression);
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos),
listElements.toArray(new SpelNodeImpl[listElements.size()]));
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
}
else if (peekToken(TokenKind.COMMA, true)) { // multi-item list
List<SpelNodeImpl> listElements = new ArrayList<>();
listElements.add(firstExpression);
List<SpelNodeImpl> elements = new ArrayList<>();
elements.add(firstExpression);
do {
listElements.add(eatExpression());
elements.add(eatExpression());
}
while (peekToken(TokenKind.COMMA, true));
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineList(toPos(t.startPos, closingCurly.endPos),
listElements.toArray(new SpelNodeImpl[listElements.size()]));
expr = new InlineList(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
}
else if (peekToken(TokenKind.COLON, true)) { // map!
List<SpelNodeImpl> mapElements = new ArrayList<>();
mapElements.add(firstExpression);
mapElements.add(eatExpression());
List<SpelNodeImpl> elements = new ArrayList<>();
elements.add(firstExpression);
elements.add(eatExpression());
while (peekToken(TokenKind.COMMA, true)) {
mapElements.add(eatExpression());
elements.add(eatExpression());
eatToken(TokenKind.COLON);
mapElements.add(eatExpression());
elements.add(eatExpression());
}
closingCurly = eatToken(TokenKind.RCURLY);
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos),
mapElements.toArray(new SpelNodeImpl[mapElements.size()]));
expr = new InlineMap(toPos(t.startPos, closingCurly.endPos), elements.toArray(new SpelNodeImpl[0]));
}
else {
throw internalException(t.startPos, SpelMessage.OOD);
@ -743,10 +740,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -743,10 +740,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
"qualified ID", node.getKind().toString().toLowerCase());
}
int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(),
qualifiedIdPieces.getLast().getEndPosition());
return new QualifiedIdentifier(pos,
qualifiedIdPieces.toArray(new SpelNodeImpl[qualifiedIdPieces.size()]));
int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition());
return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[0]));
}
private boolean isValidQualifiedId(@Nullable Token node) {
@ -812,15 +807,13 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -812,15 +807,13 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
nodes.add(pop());
}
push(new ConstructorReference(toPos(newToken),
dimensions.toArray(new SpelNodeImpl[dimensions.size()]),
nodes.toArray(new SpelNodeImpl[nodes.size()])));
dimensions.toArray(new SpelNodeImpl[0]), nodes.toArray(new SpelNodeImpl[0])));
}
else {
// regular constructor invocation
eatConstructorArgs(nodes);
// TODO correct end position?
push(new ConstructorReference(toPos(newToken),
nodes.toArray(new SpelNodeImpl[nodes.size()])));
push(new ConstructorReference(toPos(newToken), nodes.toArray(new SpelNodeImpl[0])));
}
return true;
}

2
spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java

@ -84,7 +84,7 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]> @@ -84,7 +84,7 @@ public class SortedResourcesFactoryBean extends AbstractFactoryBean<Resource[]>
});
scripts.addAll(resources);
}
return scripts.toArray(new Resource[scripts.size()]);
return scripts.toArray(new Resource[0]);
}
}

6
spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java

@ -1,5 +1,5 @@ @@ -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.
@ -462,8 +462,8 @@ public abstract class AbstractJdbcInsert { @@ -462,8 +462,8 @@ public abstract class AbstractJdbcInsert {
// clause while HSQL uses a second query that has to be executed with the same connection.
if (keyQuery.toUpperCase().startsWith("RETURNING")) {
Long key = getJdbcTemplate().queryForObject(getInsertString() + " " + keyQuery,
values.toArray(new Object[values.size()]), Long.class);
Long key = getJdbcTemplate().queryForObject(
getInsertString() + " " + keyQuery, values.toArray(), Long.class);
Map<String, Object> keys = new HashMap<>(1);
keys.put(getGeneratedKeyNames()[0], key);
keyHolder.getKeyList().add(keys);

7
spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java

@ -41,6 +41,7 @@ import javax.jms.TopicSession; @@ -41,6 +41,7 @@ import javax.jms.TopicSession;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
@ -254,10 +255,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @@ -254,10 +255,8 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
if (target instanceof TopicSession) {
classes.add(TopicSession.class);
}
return (Session) Proxy.newProxyInstance(
SessionProxy.class.getClassLoader(),
classes.toArray(new Class<?>[classes.size()]),
new CachedSessionInvocationHandler(target, sessionList));
return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(),
ClassUtils.toClassArray(classes), new CachedSessionInvocationHandler(target, sessionList));
}

4
spring-jms/src/main/java/org/springframework/jms/connection/ChainedExceptionListener.java

@ -1,5 +1,5 @@ @@ -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.
@ -48,7 +48,7 @@ public class ChainedExceptionListener implements ExceptionListener { @@ -48,7 +48,7 @@ public class ChainedExceptionListener implements ExceptionListener {
* Return all registered ExceptionListener delegates (as array).
*/
public final ExceptionListener[] getDelegates() {
return this.delegates.toArray(new ExceptionListener[this.delegates.size()]);
return this.delegates.toArray(new ExceptionListener[0]);
}

9
spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java

@ -1,5 +1,5 @@ @@ -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.
@ -42,6 +42,7 @@ import org.springframework.beans.factory.DisposableBean; @@ -42,6 +42,7 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* A JMS ConnectionFactory adapter that returns the same Connection
@ -519,10 +520,8 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti @@ -519,10 +520,8 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti
if (target instanceof TopicConnection) {
classes.add(TopicConnection.class);
}
return (Connection) Proxy.newProxyInstance(
Connection.class.getClassLoader(),
classes.toArray(new Class<?>[classes.size()]),
new SharedConnectionInvocationHandler());
return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
ClassUtils.toClassArray(classes), new SharedConnectionInvocationHandler());
}

15
spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java

@ -1,5 +1,5 @@ @@ -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.
@ -37,6 +37,7 @@ import javax.jms.TransactionInProgressException; @@ -37,6 +37,7 @@ import javax.jms.TransactionInProgressException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Proxy for a target JMS {@link javax.jms.ConnectionFactory}, adding awareness of
@ -229,10 +230,8 @@ public class TransactionAwareConnectionFactoryProxy @@ -229,10 +230,8 @@ public class TransactionAwareConnectionFactoryProxy
if (target instanceof TopicConnection) {
classes.add(TopicConnection.class);
}
return (Connection) Proxy.newProxyInstance(
Connection.class.getClassLoader(),
classes.toArray(new Class<?>[classes.size()]),
new TransactionAwareConnectionInvocationHandler(target));
return (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(),
ClassUtils.toClassArray(classes), new TransactionAwareConnectionInvocationHandler(target));
}
@ -301,10 +300,8 @@ public class TransactionAwareConnectionFactoryProxy @@ -301,10 +300,8 @@ public class TransactionAwareConnectionFactoryProxy
if (target instanceof TopicSession) {
classes.add(TopicSession.class);
}
return (Session) Proxy.newProxyInstance(
SessionProxy.class.getClassLoader(),
classes.toArray(new Class<?>[classes.size()]),
new CloseSuppressingSessionInvocationHandler(target));
return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(),
ClassUtils.toClassArray(classes), new CloseSuppressingSessionInvocationHandler(target));
}
}

5
spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

@ -418,9 +418,8 @@ public abstract class AbstractEntityManagerFactoryBean implements @@ -418,9 +418,8 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
ifcs.add(EntityManagerFactoryInfo.class);
try {
return (EntityManagerFactory) Proxy.newProxyInstance(
this.beanClassLoader, ifcs.toArray(new Class<?>[ifcs.size()]),
new ManagedEntityManagerFactoryInvocationHandler(this));
return (EntityManagerFactory) Proxy.newProxyInstance(this.beanClassLoader,
ClassUtils.toClassArray(ifcs), new ManagedEntityManagerFactoryInvocationHandler(this));
}
catch (IllegalArgumentException ex) {
if (entityManagerFactoryInterface != null) {

4
spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java

@ -1,5 +1,5 @@ @@ -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.
@ -232,7 +232,7 @@ public abstract class ExtendedEntityManagerCreator { @@ -232,7 +232,7 @@ public abstract class ExtendedEntityManagerCreator {
ifcs.add(EntityManagerProxy.class);
return (EntityManager) Proxy.newProxyInstance(
(cl != null ? cl : ExtendedEntityManagerCreator.class.getClassLoader()),
ifcs.toArray(new Class<?>[ifcs.size()]),
ClassUtils.toClassArray(ifcs),
new ExtendedEntityManagerInvocationHandler(
rawEm, exceptionTranslator, jta, containerManaged, synchronizedWithTransaction));
}

4
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

@ -1,5 +1,5 @@ @@ -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.
@ -150,7 +150,7 @@ final class PersistenceUnitReader { @@ -150,7 +150,7 @@ final class PersistenceUnitReader {
throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation);
}
return infos.toArray(new SpringPersistenceUnitInfo[infos.size()]);
return infos.toArray(new SpringPersistenceUnitInfo[0]);
}

4
spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java

@ -1,5 +1,5 @@ @@ -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.
@ -94,7 +94,7 @@ class ClassPathJaxb2TypeScanner { @@ -94,7 +94,7 @@ class ClassPathJaxb2TypeScanner {
}
}
}
return jaxb2Classes.toArray(new Class<?>[jaxb2Classes.size()]);
return ClassUtils.toClassArray(jaxb2Classes);
}
catch (IOException ex) {
throw new UncategorizedMappingException("Failed to scan classpath for unlisted classes", ex);

2
spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

@ -357,7 +357,7 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -357,7 +357,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
public Cookie[] getCookies() {
return this.cookies.toArray(new Cookie[this.cookies.size()]);
return this.cookies.toArray(new Cookie[0]);
}
@Nullable

4
spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

@ -1,5 +1,5 @@ @@ -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.
@ -149,7 +149,7 @@ public class TestContextManager { @@ -149,7 +149,7 @@ public class TestContextManager {
* @see #registerTestExecutionListeners(TestExecutionListener...)
*/
public void registerTestExecutionListeners(List<TestExecutionListener> testExecutionListeners) {
registerTestExecutionListeners(testExecutionListeners.toArray(new TestExecutionListener[testExecutionListeners.size()]));
registerTestExecutionListeners(testExecutionListeners.toArray(new TestExecutionListener[0]));
}
/**

4
spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java

@ -1,5 +1,5 @@ @@ -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.
@ -185,7 +185,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen @@ -185,7 +185,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
scriptResources.add(new ByteArrayResource(stmt.getBytes(), "from inlined SQL statement: " + stmt));
}
}
populator.setScripts(scriptResources.toArray(new Resource[scriptResources.size()]));
populator.setScripts(scriptResources.toArray(new Resource[0]));
if (logger.isDebugEnabled()) {
logger.debug("Executing SQL scripts: " + ObjectUtils.nullSafeToString(scriptResources));
}

3
spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java

@ -385,8 +385,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot @@ -385,8 +385,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
MergedTestPropertySources mergedTestPropertySources =
TestPropertySourceUtils.buildMergedTestPropertySources(testClass);
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(testClass,
StringUtils.toStringArray(locations),
ClassUtils.toClassArray(classes),
StringUtils.toStringArray(locations), ClassUtils.toClassArray(classes),
ApplicationContextInitializerUtils.resolveInitializerClasses(configAttributesList),
ActiveProfilesUtils.resolveActiveProfiles(testClass),
mergedTestPropertySources.getLocations(),

5
spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java

@ -1,5 +1,5 @@ @@ -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,6 +28,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils; @@ -28,6 +28,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.test.context.SmartContextLoader;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Utility methods for {@link SmartContextLoader SmartContextLoaders} that deal
@ -85,7 +86,7 @@ public abstract class AnnotationConfigContextLoaderUtils { @@ -85,7 +86,7 @@ public abstract class AnnotationConfigContextLoaderUtils {
}
}
return configClasses.toArray(new Class<?>[configClasses.size()]);
return ClassUtils.toClassArray(configClasses);
}
/**

5
spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java

@ -1,5 +1,5 @@ @@ -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.
@ -29,6 +29,7 @@ import org.springframework.test.context.CacheAwareContextLoaderDelegate; @@ -29,6 +29,7 @@ import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Default implementation of the {@link TestContext} interface.
@ -195,7 +196,7 @@ public class DefaultTestContext implements TestContext { @@ -195,7 +196,7 @@ public class DefaultTestContext implements TestContext {
@Override
public String[] attributeNames() {
synchronized (this.attributes) {
return this.attributes.keySet().stream().toArray(String[]::new);
return StringUtils.toStringArray(this.attributes.keySet());
}
}

4
spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

@ -1,5 +1,5 @@ @@ -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.
@ -295,7 +295,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable { @@ -295,7 +295,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
}
if (!ObjectUtils.isEmpty(cookies)) {
request.setCookies(cookies.toArray(new Cookie[cookies.size()]));
request.setCookies(cookies.toArray(new Cookie[0]));
}
}

2
spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

@ -652,7 +652,7 @@ public class MockHttpServletRequestBuilder @@ -652,7 +652,7 @@ public class MockHttpServletRequestBuilder
}
if (!ObjectUtils.isEmpty(this.cookies)) {
request.setCookies(this.cookies.toArray(new Cookie[this.cookies.size()]));
request.setCookies(this.cookies.toArray(new Cookie[0]));
}
if (!ObjectUtils.isEmpty(this.locales)) {
request.setPreferredLocales(this.locales);

6
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java

@ -1,5 +1,5 @@ @@ -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.
@ -25,6 +25,7 @@ import org.springframework.lang.Nullable; @@ -25,6 +25,7 @@ import org.springframework.lang.Nullable;
import org.springframework.mock.web.MockServletConfig;
import org.springframework.test.web.servlet.DispatcherServletCustomizer;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MockMvcBuilder;
import org.springframework.test.web.servlet.MockMvcBuilderSupport;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.ResultHandler;
@ -34,7 +35,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -34,7 +35,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.util.Assert;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.test.web.servlet.MockMvcBuilder;
/**
* Abstract implementation of {@link MockMvcBuilder} with common methods for
@ -144,7 +144,7 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B> @@ -144,7 +144,7 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
}
}
Filter[] filterArray = this.filters.toArray(new Filter[this.filters.size()]);
Filter[] filterArray = this.filters.toArray(new Filter[0]);
return super.createMockMvc(filterArray, mockServletConfig, wac, this.defaultRequestBuilder,
this.globalResultMatchers, this.globalResultHandlers, this.dispatcherServletCustomizers);

4
spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java

@ -1,5 +1,5 @@ @@ -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.
@ -50,7 +50,7 @@ public class ChainedPersistenceExceptionTranslator implements PersistenceExcepti @@ -50,7 +50,7 @@ public class ChainedPersistenceExceptionTranslator implements PersistenceExcepti
* Return all registered PersistenceExceptionTranslator delegates (as array).
*/
public final PersistenceExceptionTranslator[] getDelegates() {
return this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]);
return this.delegates.toArray(new PersistenceExceptionTranslator[0]);
}

4
spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java

@ -1,5 +1,5 @@ @@ -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.
@ -103,7 +103,7 @@ final class DefaultSslInfo implements SslInfo { @@ -103,7 +103,7 @@ final class DefaultSslInfo implements SslInfo {
result.add((X509Certificate) certificate);
}
}
return !result.isEmpty() ? result.toArray(new X509Certificate[result.size()]) : null;
return (!result.isEmpty() ? result.toArray(new X509Certificate[0]) : null);
}
}

2
spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java

@ -213,7 +213,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe @@ -213,7 +213,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
logger.info("Registering annotated classes: [" +
StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + "]");
}
reader.register(this.annotatedClasses.toArray(new Class<?>[this.annotatedClasses.size()]));
reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
if (!this.basePackages.isEmpty()) {

6
spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java

@ -1,5 +1,5 @@ @@ -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.
@ -93,7 +93,7 @@ public abstract class MultipartResolutionDelegate { @@ -93,7 +93,7 @@ public abstract class MultipartResolutionDelegate {
}
if (multipartRequest != null) {
List<MultipartFile> multipartFiles = multipartRequest.getFiles(name);
return multipartFiles.toArray(new MultipartFile[multipartFiles.size()]);
return multipartFiles.toArray(new MultipartFile[0]);
}
else {
return null;
@ -164,7 +164,7 @@ public abstract class MultipartResolutionDelegate { @@ -164,7 +164,7 @@ public abstract class MultipartResolutionDelegate {
result.add(part);
}
}
return result.toArray(new Part[result.size()]);
return result.toArray(new Part[0]);
}
}

10
spring-web/src/main/java/org/springframework/web/server/handler/FilteringWebHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -21,14 +21,13 @@ import java.util.List; @@ -21,14 +21,13 @@ import java.util.List;
import reactor.core.publisher.Mono;
import org.springframework.util.CollectionUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebHandler;
/**
* WebHandler decorator that invokes a chain of {@link WebFilter}s before the
* delegate {@link WebHandler}.
* {@link WebHandler} decorator that invokes a chain of {@link WebFilter}s
* before the delegate {@link WebHandler}.
*
* @author Rossen Stoyanchev
* @since 5.0
@ -44,8 +43,7 @@ public class FilteringWebHandler extends WebHandlerDecorator { @@ -44,8 +43,7 @@ public class FilteringWebHandler extends WebHandlerDecorator {
*/
public FilteringWebHandler(WebHandler webHandler, List<WebFilter> filters) {
super(webHandler);
this.filters = !CollectionUtils.isEmpty(filters) ?
filters.toArray(new WebFilter[filters.size()]) : new WebFilter[0];
this.filters = filters.toArray(new WebFilter[0]);
}

2
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

@ -349,7 +349,7 @@ public class MockHttpServletResponse implements HttpServletResponse { @@ -349,7 +349,7 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
public Cookie[] getCookies() {
return this.cookies.toArray(new Cookie[this.cookies.size()]);
return this.cookies.toArray(new Cookie[0]);
}
public Cookie getCookie(String name) {

4
spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -223,7 +223,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { @@ -223,7 +223,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
PathResourceResolver resolver = (PathResourceResolver) getResourceResolvers().get(i);
if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) {
resolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
resolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
}
break;
}

4
spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java

@ -1,5 +1,5 @@ @@ -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.
@ -116,7 +116,7 @@ public class HandlerExecutionChain { @@ -116,7 +116,7 @@ public class HandlerExecutionChain {
@Nullable
public HandlerInterceptor[] getInterceptors() {
if (this.interceptors == null && this.interceptorList != null) {
this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]);
this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[0]);
}
return this.interceptors;
}

11
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

@ -1,5 +1,5 @@ @@ -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.
@ -317,8 +317,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -317,8 +317,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
*/
@Nullable
protected final HandlerInterceptor[] getAdaptedInterceptors() {
int count = this.adaptedInterceptors.size();
return (count > 0 ? this.adaptedInterceptors.toArray(new HandlerInterceptor[count]) : null);
return (!this.adaptedInterceptors.isEmpty() ?
this.adaptedInterceptors.toArray(new HandlerInterceptor[0]) : null);
}
/**
@ -327,14 +327,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -327,14 +327,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
*/
@Nullable
protected final MappedInterceptor[] getMappedInterceptors() {
List<MappedInterceptor> mappedInterceptors = new ArrayList<>();
List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size());
for (HandlerInterceptor interceptor : this.adaptedInterceptors) {
if (interceptor instanceof MappedInterceptor) {
mappedInterceptors.add((MappedInterceptor) interceptor);
}
}
int count = mappedInterceptors.size();
return (count > 0 ? mappedInterceptors.toArray(new MappedInterceptor[count]) : null);
return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null);
}

29
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

@ -1,5 +1,5 @@ @@ -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.
@ -47,7 +47,6 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage @@ -47,7 +47,6 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.ui.ModelMap;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
import org.springframework.web.accept.ContentNegotiationManager;
@ -151,7 +150,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -151,7 +150,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
private DeferredResultProcessingInterceptor[] deferredResultInterceptors = new DeferredResultProcessingInterceptor[0];
private ReactiveAdapterRegistry reactiveRegistry = ReactiveAdapterRegistry.getSharedInstance();
private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
private boolean ignoreDefaultModelOnRedirect = false;
@ -410,8 +409,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -410,8 +409,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* @param interceptors the interceptors to register
*/
public void setCallableInterceptors(List<CallableProcessingInterceptor> interceptors) {
Assert.notNull(interceptors, "CallableProcessingInterceptor List must not be null");
this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[interceptors.size()]);
this.callableInterceptors = interceptors.toArray(new CallableProcessingInterceptor[0]);
}
/**
@ -419,18 +417,27 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -419,18 +417,27 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* @param interceptors the interceptors to register
*/
public void setDeferredResultInterceptors(List<DeferredResultProcessingInterceptor> interceptors) {
Assert.notNull(interceptors, "DeferredResultProcessingInterceptor List must not be null");
this.deferredResultInterceptors = interceptors.toArray(new DeferredResultProcessingInterceptor[interceptors.size()]);
this.deferredResultInterceptors = interceptors.toArray(new DeferredResultProcessingInterceptor[0]);
}
/**
* Configure the registry for reactive library types to be supported as
* return values from controller methods.
* @since 5.0
* @deprecated as of 5.0.5, in favor of {@link #setReactiveAdapterRegistry}
*/
@Deprecated
public void setReactiveRegistry(ReactiveAdapterRegistry reactiveRegistry) {
Assert.notNull(reactiveRegistry, "ReactiveAdapterRegistry is required");
this.reactiveRegistry = reactiveRegistry;
this.reactiveAdapterRegistry = reactiveRegistry;
}
/**
* Configure the registry for reactive library types to be supported as
* return values from controller methods.
* @since 5.0.5
*/
public void setReactiveAdapterRegistry(ReactiveAdapterRegistry reactiveAdapterRegistry) {
this.reactiveAdapterRegistry = reactiveAdapterRegistry;
}
/**
@ -438,7 +445,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -438,7 +445,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* @since 5.0
*/
public ReactiveAdapterRegistry getReactiveAdapterRegistry() {
return this.reactiveRegistry;
return this.reactiveAdapterRegistry;
}
/**
@ -702,7 +709,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter @@ -702,7 +709,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
handlers.add(new ModelMethodProcessor());
handlers.add(new ViewMethodReturnValueHandler());
handlers.add(new ResponseBodyEmitterReturnValueHandler(getMessageConverters(),
this.reactiveRegistry, this.taskExecutor, this.contentNegotiationManager));
this.reactiveAdapterRegistry, this.taskExecutor, this.contentNegotiationManager));
handlers.add(new StreamingResponseBodyReturnValueHandler());
handlers.add(new HttpEntityMethodProcessor(getMessageConverters(),
this.contentNegotiationManager, this.requestResponseBodyAdvice));

4
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

@ -1,5 +1,5 @@ @@ -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.
@ -387,7 +387,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator @@ -387,7 +387,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
pathResolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
pathResolver.setAllowedLocations(getLocations().toArray(new Resource[0]));
}
if (this.urlPathHelper != null) {
pathResolver.setLocationCharsets(this.locationCharsets);

2
spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java

@ -180,7 +180,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration @@ -180,7 +180,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
}
ClassLoader classLoader = getApplicationContext().getClassLoader();
Assert.state(classLoader != null, "No ClassLoader");
return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader) : classLoader);
return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[0]), classLoader) : classLoader);
}
/**

2
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java

@ -135,7 +135,7 @@ public abstract class AbstractWebSocketHandlerRegistration<M> implements WebSock @@ -135,7 +135,7 @@ public abstract class AbstractWebSocketHandlerRegistration<M> implements WebSock
List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1);
interceptors.addAll(this.interceptors);
interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins));
return interceptors.toArray(new HandshakeInterceptor[interceptors.size()]);
return interceptors.toArray(new HandshakeInterceptor[0]);
}
/**

11
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java

@ -62,8 +62,8 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @@ -62,8 +62,8 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
private SockJsServiceRegistration registration;
public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler,
TaskScheduler sockJsTaskScheduler) {
public WebMvcStompWebSocketEndpointRegistration(
String[] paths, WebSocketHandler webSocketHandler, TaskScheduler sockJsTaskScheduler) {
Assert.notEmpty(paths, "No paths specified");
Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
@ -76,7 +76,6 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @@ -76,7 +76,6 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
@Override
public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) {
Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null");
this.handshakeHandler = handshakeHandler;
return this;
}
@ -117,10 +116,10 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @@ -117,10 +116,10 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
}
protected HandshakeInterceptor[] getInterceptors() {
List<HandshakeInterceptor> interceptors = new ArrayList<>();
List<HandshakeInterceptor> interceptors = new ArrayList<>(this.interceptors.size() + 1);
interceptors.addAll(this.interceptors);
interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins));
return interceptors.toArray(new HandshakeInterceptor[interceptors.size()]);
return interceptors.toArray(new HandshakeInterceptor[0]);
}
public final MultiValueMap<HttpRequestHandler, String> getMappings() {
@ -128,7 +127,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @@ -128,7 +127,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
if (this.registration != null) {
SockJsService sockJsService = this.registration.getSockJsService();
for (String path : this.paths) {
String pattern = path.endsWith("/") ? path + "**" : path + "/**";
String pattern = (path.endsWith("/") ? path + "**" : path + "/**");
SockJsHttpRequestHandler handler = new SockJsHttpRequestHandler(sockJsService, this.webSocketHandler);
mappings.add(handler, pattern);
}

Loading…
Cancel
Save