Skip to content

Commit a5cbf5f

Browse files
committed
Consistent use of Collection.toArray with zero-sized array argument
Includes consistent use of ClassUtils.toClassArray (as non-null variant) Issue: SPR-16523
1 parent 1ab3f88 commit a5cbf5f

File tree

72 files changed

+209
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+209
-234
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -253,8 +253,8 @@ private AspectComponentDefinition createAspectComponentDefinition(
253253
Element aspectElement, String aspectId, List<BeanDefinition> beanDefs,
254254
List<BeanReference> beanRefs, ParserContext parserContext) {
255255

256-
BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[beanDefs.size()]);
257-
BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[beanRefs.size()]);
256+
BeanDefinition[] beanDefArray = beanDefs.toArray(new BeanDefinition[0]);
257+
BeanReference[] beanRefArray = beanRefs.toArray(new BeanReference[0]);
258258
Object source = parserContext.extractSource(aspectElement);
259259
return new AspectComponentDefinition(aspectId, beanDefArray, beanRefArray, source);
260260
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -228,7 +228,7 @@ public boolean removeInterface(Class<?> intf) {
228228

229229
@Override
230230
public Class<?>[] getProxiedInterfaces() {
231-
return this.interfaces.toArray(new Class<?>[this.interfaces.size()]);
231+
return ClassUtils.toClassArray(this.interfaces);
232232
}
233233

234234
@Override
@@ -372,7 +372,7 @@ private void addAdvisorInternal(int pos, Advisor advisor) throws AopConfigExcept
372372
* Bring the array up to date with the list.
373373
*/
374374
protected final void updateAdvisorArray() {
375-
this.advisorArray = this.advisors.toArray(new Advisor[this.advisors.size()]);
375+
this.advisorArray = this.advisors.toArray(new Advisor[0]);
376376
}
377377

378378
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdvice
9090
if (interceptors.isEmpty()) {
9191
throw new UnknownAdviceTypeException(advisor.getAdvice());
9292
}
93-
return interceptors.toArray(new MethodInterceptor[interceptors.size()]);
93+
return interceptors.toArray(new MethodInterceptor[0]);
9494
}
9595

9696
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ private Advisor[] resolveInterceptorNames() {
554554
advisors.add(this.advisorAdapterRegistry.wrap(next));
555555
}
556556
}
557-
return advisors.toArray(new Advisor[advisors.size()]);
557+
return advisors.toArray(new Advisor[0]);
558558
}
559559

560560
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@ public void addInterface(Class<?> intf) {
105105

106106
@Override
107107
public Class<?>[] getInterfaces() {
108-
return this.interfaces.toArray(new Class<?>[this.interfaces.size()]);
108+
return ClassUtils.toClassArray(this.interfaces);
109109
}
110110

111111
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void suppressInterface(Class<?> intf) {
6161

6262
@Override
6363
public Class<?>[] getInterfaces() {
64-
return this.publishedInterfaces.toArray(new Class<?>[this.publishedInterfaces.size()]);
64+
return ClassUtils.toClassArray(this.publishedInterfaces);
6565
}
6666

6767
/**

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -118,8 +118,7 @@ public void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean
118118

119119
// If we encountered individual exceptions, throw the composite exception.
120120
if (propertyAccessExceptions != null) {
121-
PropertyAccessException[] paeArray =
122-
propertyAccessExceptions.toArray(new PropertyAccessException[propertyAccessExceptions.size()]);
121+
PropertyAccessException[] paeArray = propertyAccessExceptions.toArray(new PropertyAccessException[0]);
123122
throw new PropertyBatchUpdateException(paeArray);
124123
}
125124
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -220,7 +220,7 @@ private String propertyNameFor(Method method) {
220220
*/
221221
@Override
222222
public PropertyDescriptor[] getPropertyDescriptors() {
223-
return this.propertyDescriptors.toArray(new PropertyDescriptor[this.propertyDescriptors.size()]);
223+
return this.propertyDescriptors.toArray(new PropertyDescriptor[0]);
224224
}
225225

226226
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -246,7 +246,7 @@ public void removePropertyValue(String propertyName) {
246246

247247
@Override
248248
public PropertyValue[] getPropertyValues() {
249-
return this.propertyValueList.toArray(new PropertyValue[this.propertyValueList.size()]);
249+
return this.propertyValueList.toArray(new PropertyValue[0]);
250250
}
251251

252252
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -149,7 +149,7 @@ public Throwable[] getRelatedCauses() {
149149
if (this.relatedCauses == null) {
150150
return null;
151151
}
152-
return this.relatedCauses.toArray(new Throwable[this.relatedCauses.size()]);
152+
return this.relatedCauses.toArray(new Throwable[0]);
153153
}
154154

155155

0 commit comments

Comments
 (0)