Commit 4b9c3c13 authored by Phillip Webb's avatar Phillip Webb

Polish Collection.toArray

Consistently use `StringUtils.toStringArray`, `ClassUtils.toClassArray`
or zero length when converting collections to arrays.

Fixes gh-12160
parent 358adcd6
...@@ -32,6 +32,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader; ...@@ -32,6 +32,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.util.StringUtils;
/** /**
* Selects configuration classes for the management context configuration. Entries are * Selects configuration classes for the management context configuration. Entries are
...@@ -65,7 +66,7 @@ class ManagementContextConfigurationImportSelector ...@@ -65,7 +66,7 @@ class ManagementContextConfigurationImportSelector
names.add(configuration.getClassName()); names.add(configuration.getClassName());
} }
} }
return names.toArray(new String[names.size()]); return StringUtils.toStringArray(names);
} }
private List<ManagementConfiguration> getConfigurations() { private List<ManagementConfiguration> getConfigurations() {
......
...@@ -32,6 +32,7 @@ import org.springframework.boot.web.context.ConfigurableWebServerApplicationCont ...@@ -32,6 +32,7 @@ import org.springframework.boot.web.context.ConfigurableWebServerApplicationCont
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.util.ClassUtils;
/** /**
* A {@link ManagementContextFactory} for servlet-based web applications. * A {@link ManagementContextFactory} for servlet-based web applications.
...@@ -47,7 +48,7 @@ class ServletManagementContextFactory implements ManagementContextFactory { ...@@ -47,7 +48,7 @@ class ServletManagementContextFactory implements ManagementContextFactory {
child.setParent(parent); child.setParent(parent);
List<Class<?>> combinedClasses = new ArrayList<>(Arrays.asList(configClasses)); List<Class<?>> combinedClasses = new ArrayList<>(Arrays.asList(configClasses));
combinedClasses.add(ServletWebServerFactoryAutoConfiguration.class); combinedClasses.add(ServletWebServerFactoryAutoConfiguration.class);
child.register(combinedClasses.toArray(new Class<?>[combinedClasses.size()])); child.register(ClassUtils.toClassArray(combinedClasses));
registerServletWebServerFactory(parent, child); registerServletWebServerFactory(parent, child);
return child; return child;
} }
......
...@@ -30,6 +30,7 @@ import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfi ...@@ -30,6 +30,7 @@ import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfi
import org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.management.ThreadDumpEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceEndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.mappings.MappingsEndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.web.mappings.MappingsEndpointAutoConfiguration;
import org.springframework.util.ClassUtils;
/** /**
* A list of all endpoint auto-configuration classes for use in tests. * A list of all endpoint auto-configuration classes for use in tests.
...@@ -51,7 +52,7 @@ final class EndpointAutoConfigurationClasses { ...@@ -51,7 +52,7 @@ final class EndpointAutoConfigurationClasses {
all.add(ThreadDumpEndpointAutoConfiguration.class); all.add(ThreadDumpEndpointAutoConfiguration.class);
all.add(HttpTraceEndpointAutoConfiguration.class); all.add(HttpTraceEndpointAutoConfiguration.class);
all.add(MappingsEndpointAutoConfiguration.class); all.add(MappingsEndpointAutoConfiguration.class);
ALL = all.toArray(new Class<?>[] {}); ALL = ClassUtils.toClassArray(all);
} }
private EndpointAutoConfigurationClasses() { private EndpointAutoConfigurationClasses() {
......
...@@ -27,6 +27,7 @@ import org.springframework.boot.actuate.health.AbstractHealthIndicator; ...@@ -27,6 +27,7 @@ import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* {@link HealthIndicator} for an Elasticsearch cluster. * {@link HealthIndicator} for an Elasticsearch cluster.
...@@ -53,8 +54,8 @@ public class ElasticsearchHealthIndicator extends AbstractHealthIndicator { ...@@ -53,8 +54,8 @@ public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {
*/ */
public ElasticsearchHealthIndicator(Client client, long responseTimeout, public ElasticsearchHealthIndicator(Client client, long responseTimeout,
List<String> indices) { List<String> indices) {
this(client, responseTimeout, (indices == null ? null this(client, responseTimeout,
: indices.toArray(new String[indices.size()]))); (indices == null ? null : StringUtils.toStringArray(indices)));
} }
/** /**
......
...@@ -94,23 +94,18 @@ public class JerseyEndpointResourceFactory { ...@@ -94,23 +94,18 @@ public class JerseyEndpointResourceFactory {
Builder resourceBuilder = Resource.builder() Builder resourceBuilder = Resource.builder()
.path(endpointMapping.createSubPath(requestPredicate.getPath())); .path(endpointMapping.createSubPath(requestPredicate.getPath()));
resourceBuilder.addMethod(requestPredicate.getHttpMethod().name()) resourceBuilder.addMethod(requestPredicate.getHttpMethod().name())
.consumes(toStringArray(requestPredicate.getConsumes())) .consumes(StringUtils.toStringArray(requestPredicate.getConsumes()))
.produces(toStringArray(requestPredicate.getProduces())) .produces(StringUtils.toStringArray(requestPredicate.getProduces()))
.handledBy(new OperationInflector(operation, .handledBy(new OperationInflector(operation,
!requestPredicate.getConsumes().isEmpty())); !requestPredicate.getConsumes().isEmpty()));
return resourceBuilder.build(); return resourceBuilder.build();
} }
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private Resource createEndpointLinksResource(String endpointPath, private Resource createEndpointLinksResource(String endpointPath,
EndpointMediaTypes endpointMediaTypes, EndpointLinksResolver linksResolver) { EndpointMediaTypes endpointMediaTypes, EndpointLinksResolver linksResolver) {
Builder resourceBuilder = Resource.builder().path(endpointPath); Builder resourceBuilder = Resource.builder().path(endpointPath);
resourceBuilder.addMethod("GET") resourceBuilder.addMethod("GET")
.produces(endpointMediaTypes.getProduced() .produces(StringUtils.toStringArray(endpointMediaTypes.getProduced()))
.toArray(new String[endpointMediaTypes.getProduced().size()]))
.handledBy(new EndpointLinksInflector(linksResolver)); .handledBy(new EndpointLinksInflector(linksResolver));
return resourceBuilder.build(); return resourceBuilder.build();
} }
......
...@@ -167,25 +167,20 @@ public abstract class AbstractWebFluxEndpointHandlerMapping ...@@ -167,25 +167,20 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.valueOf(predicate.getHttpMethod().name())); RequestMethod.valueOf(predicate.getHttpMethod().name()));
ConsumesRequestCondition consumes = new ConsumesRequestCondition( ConsumesRequestCondition consumes = new ConsumesRequestCondition(
toStringArray(predicate.getConsumes())); StringUtils.toStringArray(predicate.getConsumes()));
ProducesRequestCondition produces = new ProducesRequestCondition( ProducesRequestCondition produces = new ProducesRequestCondition(
toStringArray(predicate.getProduces())); StringUtils.toStringArray(predicate.getProduces()));
return new RequestMappingInfo(null, patterns, methods, null, null, consumes, return new RequestMappingInfo(null, patterns, methods, null, null, consumes,
produces, null); produces, null);
} }
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private void registerLinksMapping() { private void registerLinksMapping() {
PatternsRequestCondition patterns = new PatternsRequestCondition( PatternsRequestCondition patterns = new PatternsRequestCondition(
pathPatternParser.parse(this.endpointMapping.getPath())); pathPatternParser.parse(this.endpointMapping.getPath()));
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.GET); RequestMethod.GET);
ProducesRequestCondition produces = new ProducesRequestCondition( ProducesRequestCondition produces = new ProducesRequestCondition(
this.endpointMediaTypes.getProduced().toArray( StringUtils.toStringArray(this.endpointMediaTypes.getProduced()));
new String[this.endpointMediaTypes.getProduced().size()]));
RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null, RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null,
null, produces, null); null, produces, null);
registerMapping(mapping, this, this.linksMethod); registerMapping(mapping, this, this.linksMethod);
......
...@@ -155,24 +155,20 @@ public abstract class AbstractWebMvcEndpointHandlerMapping ...@@ -155,24 +155,20 @@ public abstract class AbstractWebMvcEndpointHandlerMapping
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.valueOf(predicate.getHttpMethod().name())); RequestMethod.valueOf(predicate.getHttpMethod().name()));
ConsumesRequestCondition consumes = new ConsumesRequestCondition( ConsumesRequestCondition consumes = new ConsumesRequestCondition(
toStringArray(predicate.getConsumes())); StringUtils.toStringArray(predicate.getConsumes()));
ProducesRequestCondition produces = new ProducesRequestCondition( ProducesRequestCondition produces = new ProducesRequestCondition(
toStringArray(predicate.getProduces())); StringUtils.toStringArray(predicate.getProduces()));
return new RequestMappingInfo(null, patterns, methods, null, null, consumes, return new RequestMappingInfo(null, patterns, methods, null, null, consumes,
produces, null); produces, null);
} }
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private void registerLinksMapping() { private void registerLinksMapping() {
PatternsRequestCondition patterns = patternsRequestConditionForPattern(""); PatternsRequestCondition patterns = patternsRequestConditionForPattern("");
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.GET); RequestMethod.GET);
ProducesRequestCondition produces = new ProducesRequestCondition( ProducesRequestCondition produces = new ProducesRequestCondition(
this.endpointMediaTypes.getProduced().toArray( this.endpointMediaTypes.getProduced().toArray(StringUtils
new String[this.endpointMediaTypes.getProduced().size()])); .toStringArray(this.endpointMediaTypes.getProduced())));
RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null, RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null,
null, produces, null); null, produces, null);
registerMapping(mapping, this, this.linksMethod); registerMapping(mapping, this, this.linksMethod);
......
...@@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContext; ...@@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -177,8 +178,7 @@ public class ConfigurationPropertiesReportEndpointTests { ...@@ -177,8 +178,7 @@ public class ConfigurationPropertiesReportEndpointTests {
ConfigurationPropertiesReportEndpoint endpoint = context ConfigurationPropertiesReportEndpoint endpoint = context
.getBean(ConfigurationPropertiesReportEndpoint.class); .getBean(ConfigurationPropertiesReportEndpoint.class);
if (!CollectionUtils.isEmpty(keysToSanitize)) { if (!CollectionUtils.isEmpty(keysToSanitize)) {
endpoint.setKeysToSanitize( endpoint.setKeysToSanitize(StringUtils.toStringArray(keysToSanitize));
keysToSanitize.toArray(new String[keysToSanitize.size()]));
} }
properties.accept(context, endpoint.configurationProperties().getContexts() properties.accept(context, endpoint.configurationProperties().getContexts()
.get(context.getId())); .get(context.getId()));
......
...@@ -264,7 +264,7 @@ public class EndpointDiscovererTests { ...@@ -264,7 +264,7 @@ public class EndpointDiscovererTests {
methods.add(findTestEndpointMethod("getOne", String.class)); methods.add(findTestEndpointMethod("getOne", String.class));
methods.add(findTestEndpointMethod("update", String.class, String.class)); methods.add(findTestEndpointMethod("update", String.class, String.class));
methods.add(findTestEndpointMethod("deleteOne", String.class)); methods.add(findTestEndpointMethod("deleteOne", String.class));
return methods.toArray(new Method[] {}); return methods.toArray(new Method[0]);
} }
private Method findTestEndpointMethod(String name, Class<?>... paramTypes) { private Method findTestEndpointMethod(String name, Class<?>... paramTypes) {
......
...@@ -47,6 +47,7 @@ import org.springframework.context.ApplicationContext; ...@@ -47,6 +47,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
/** /**
* {@link BlockJUnit4ClassRunner} for Jersey. * {@link BlockJUnit4ClassRunner} for Jersey.
...@@ -63,7 +64,7 @@ class JerseyEndpointsRunner extends AbstractWebEndpointRunner { ...@@ -63,7 +64,7 @@ class JerseyEndpointsRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) { private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(); AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
classes.add(JerseyEndpointConfiguration.class); classes.add(JerseyEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()])); context.register(ClassUtils.toClassArray(classes));
context.refresh(); context.refresh();
return context; return context;
} }
......
...@@ -44,6 +44,7 @@ import org.springframework.context.annotation.Bean; ...@@ -44,6 +44,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.ClassUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
...@@ -62,7 +63,7 @@ class WebFluxEndpointsRunner extends AbstractWebEndpointRunner { ...@@ -62,7 +63,7 @@ class WebFluxEndpointsRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) { private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext(); AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext();
classes.add(WebFluxEndpointConfiguration.class); classes.add(WebFluxEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()])); context.register(ClassUtils.toClassArray(classes));
context.refresh(); context.refresh();
return context; return context;
} }
......
...@@ -43,6 +43,7 @@ import org.springframework.context.ConfigurableApplicationContext; ...@@ -43,6 +43,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.ClassUtils;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
/** /**
...@@ -60,7 +61,7 @@ class WebMvcEndpointRunner extends AbstractWebEndpointRunner { ...@@ -60,7 +61,7 @@ class WebMvcEndpointRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) { private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(); AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
classes.add(WebMvcEndpointConfiguration.class); classes.add(WebMvcEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()])); context.register(ClassUtils.toClassArray(classes));
context.refresh(); context.refresh();
return context; return context;
} }
......
...@@ -50,6 +50,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; ...@@ -50,6 +50,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/** /**
* {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration * {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration
...@@ -100,7 +101,7 @@ public class AutoConfigurationImportSelector ...@@ -100,7 +101,7 @@ public class AutoConfigurationImportSelector
configurations.removeAll(exclusions); configurations.removeAll(exclusions);
configurations = filter(configurations, autoConfigurationMetadata); configurations = filter(configurations, autoConfigurationMetadata);
fireAutoConfigurationImportEvents(configurations, exclusions); fireAutoConfigurationImportEvents(configurations, exclusions);
return configurations.toArray(new String[configurations.size()]); return StringUtils.toStringArray(configurations);
} }
catch (IOException ex) { catch (IOException ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
...@@ -235,7 +236,7 @@ public class AutoConfigurationImportSelector ...@@ -235,7 +236,7 @@ public class AutoConfigurationImportSelector
private List<String> filter(List<String> configurations, private List<String> filter(List<String> configurations,
AutoConfigurationMetadata autoConfigurationMetadata) { AutoConfigurationMetadata autoConfigurationMetadata) {
long startTime = System.nanoTime(); long startTime = System.nanoTime();
String[] candidates = configurations.toArray(new String[configurations.size()]); String[] candidates = StringUtils.toStringArray(configurations);
boolean[] skip = new boolean[candidates.length]; boolean[] skip = new boolean[candidates.length];
boolean skipped = false; boolean skipped = false;
for (AutoConfigurationImportFilter filter : getAutoConfigurationImportFilters()) { for (AutoConfigurationImportFilter filter : getAutoConfigurationImportFilters()) {
......
...@@ -114,7 +114,7 @@ public abstract class AutoConfigurationPackages { ...@@ -114,7 +114,7 @@ public abstract class AutoConfigurationPackages {
Set<String> merged = new LinkedHashSet<>(); Set<String> merged = new LinkedHashSet<>();
merged.addAll(Arrays.asList(existing)); merged.addAll(Arrays.asList(existing));
merged.addAll(Arrays.asList(packageNames)); merged.addAll(Arrays.asList(packageNames));
return merged.toArray(new String[merged.size()]); return StringUtils.toStringArray(merged);
} }
/** /**
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -32,6 +32,7 @@ import org.springframework.cache.CacheManager; ...@@ -32,6 +32,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/** /**
* Couchbase cache configuration. * Couchbase cache configuration.
...@@ -66,7 +67,7 @@ public class CouchbaseCacheConfiguration { ...@@ -66,7 +67,7 @@ public class CouchbaseCacheConfiguration {
Couchbase couchbase = this.cacheProperties.getCouchbase(); Couchbase couchbase = this.cacheProperties.getCouchbase();
PropertyMapper.get().from(couchbase::getExpiration).whenNonNull() PropertyMapper.get().from(couchbase::getExpiration).whenNonNull()
.asInt(Duration::getSeconds).to(builder::withExpiration); .asInt(Duration::getSeconds).to(builder::withExpiration);
String[] names = cacheNames.toArray(new String[cacheNames.size()]); String[] names = StringUtils.toStringArray(cacheNames);
CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(builder, names); CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(builder, names);
return this.customizers.customize(cacheManager); return this.customizers.customize(cacheManager);
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties ...@@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Cassandra. * {@link EnableAutoConfiguration Auto-configuration} for Cassandra.
...@@ -80,7 +81,7 @@ public class CassandraAutoConfiguration { ...@@ -80,7 +81,7 @@ public class CassandraAutoConfiguration {
map.from(properties::isSsl).whenTrue().toCall(builder::withSSL); map.from(properties::isSsl).whenTrue().toCall(builder::withSSL);
map.from(this::getPoolingOptions).to(builder::withPoolingOptions); map.from(this::getPoolingOptions).to(builder::withPoolingOptions);
map.from(properties::getContactPoints) map.from(properties::getContactPoints)
.as((list) -> list.toArray(new String[list.size()])) .as((list) -> StringUtils.toStringArray(list))
.to(builder::addContactPoints); .to(builder::addContactPoints);
customize(builder); customize(builder);
return builder.build(); return builder.build();
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -40,6 +40,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -40,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager; import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor; import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
...@@ -106,7 +107,7 @@ public class Neo4jDataAutoConfiguration { ...@@ -106,7 +107,7 @@ public class Neo4jDataAutoConfiguration {
if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) { if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) {
packages = AutoConfigurationPackages.get(applicationContext); packages = AutoConfigurationPackages.get(applicationContext);
} }
return packages.toArray(new String[packages.size()]); return StringUtils.toStringArray(packages);
} }
@Configuration @Configuration
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -120,7 +120,7 @@ public class EntityScanPackages { ...@@ -120,7 +120,7 @@ public class EntityScanPackages {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(EntityScanPackages.class); beanDefinition.setBeanClass(EntityScanPackages.class);
beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0,
packageNames.toArray(new String[packageNames.size()])); StringUtils.toStringArray(packageNames));
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN, beanDefinition); registry.registerBeanDefinition(BEAN, beanDefinition);
} }
...@@ -134,7 +134,7 @@ public class EntityScanPackages { ...@@ -134,7 +134,7 @@ public class EntityScanPackages {
Set<String> merged = new LinkedHashSet<>(); Set<String> merged = new LinkedHashSet<>();
merged.addAll(Arrays.asList(existing)); merged.addAll(Arrays.asList(existing));
merged.addAll(packageNames); merged.addAll(packageNames);
return merged.toArray(new String[merged.size()]); return StringUtils.toStringArray(merged);
} }
/** /**
......
...@@ -57,6 +57,7 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; ...@@ -57,6 +57,7 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Flyway database migrations. * {@link EnableAutoConfiguration Auto-configuration} for Flyway database migrations.
...@@ -137,7 +138,7 @@ public class FlywayAutoConfiguration { ...@@ -137,7 +138,7 @@ public class FlywayAutoConfiguration {
String password = getProperty(this.properties::getPassword, String password = getProperty(this.properties::getPassword,
this.dataSourceProperties::getPassword); this.dataSourceProperties::getPassword);
flyway.setDataSource(url, user, password, flyway.setDataSource(url, user, password,
this.properties.getInitSqls().toArray(new String[0])); StringUtils.toStringArray(this.properties.getInitSqls()));
} }
else if (this.flywayDataSource != null) { else if (this.flywayDataSource != null) {
flyway.setDataSource(this.flywayDataSource); flyway.setDataSource(this.flywayDataSource);
...@@ -145,8 +146,7 @@ public class FlywayAutoConfiguration { ...@@ -145,8 +146,7 @@ public class FlywayAutoConfiguration {
else { else {
flyway.setDataSource(this.dataSource); flyway.setDataSource(this.dataSource);
} }
flyway.setCallbacks(this.flywayCallbacks flyway.setCallbacks(this.flywayCallbacks.toArray(new FlywayCallback[0]));
.toArray(new FlywayCallback[this.flywayCallbacks.size()]));
String[] locations = new LocationResolver(flyway.getDataSource()) String[] locations = new LocationResolver(flyway.getDataSource())
.resolveLocations(this.properties.getLocations()); .resolveLocations(this.properties.getLocations());
checkLocationExists(locations); checkLocationExists(locations);
...@@ -241,7 +241,7 @@ public class FlywayAutoConfiguration { ...@@ -241,7 +241,7 @@ public class FlywayAutoConfiguration {
} }
public String[] resolveLocations(Collection<String> locations) { public String[] resolveLocations(Collection<String> locations) {
return resolveLocations(locations.toArray(new String[locations.size()])); return resolveLocations(StringUtils.toStringArray(locations));
} }
public String[] resolveLocations(String[] locations) { public String[] resolveLocations(String[] locations) {
......
...@@ -337,8 +337,7 @@ public class JacksonAutoConfiguration { ...@@ -337,8 +337,7 @@ public class JacksonAutoConfiguration {
private void configureModules(Jackson2ObjectMapperBuilder builder) { private void configureModules(Jackson2ObjectMapperBuilder builder) {
Collection<Module> moduleBeans = getBeans(this.applicationContext, Collection<Module> moduleBeans = getBeans(this.applicationContext,
Module.class); Module.class);
builder.modulesToInstall( builder.modulesToInstall(moduleBeans.toArray(new Module[0]));
moduleBeans.toArray(new Module[moduleBeans.size()]));
} }
private void configureLocale(Jackson2ObjectMapperBuilder builder) { private void configureLocale(Jackson2ObjectMapperBuilder builder) {
......
...@@ -113,7 +113,7 @@ public class EmbeddedLdapAutoConfiguration { ...@@ -113,7 +113,7 @@ public class EmbeddedLdapAutoConfiguration {
@Bean @Bean
public InMemoryDirectoryServer directoryServer() throws LDAPException { public InMemoryDirectoryServer directoryServer() throws LDAPException {
String[] baseDn = this.embeddedProperties.getBaseDn().toArray(new String[0]); String[] baseDn = StringUtils.toStringArray(this.embeddedProperties.getBaseDn());
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDn); InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDn);
if (hasCredentials(this.embeddedProperties.getCredential())) { if (hasCredentials(this.embeddedProperties.getCredential())) {
config.addAdditionalBindCredentials( config.addAdditionalBindCredentials(
......
...@@ -55,6 +55,7 @@ import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; ...@@ -55,6 +55,7 @@ import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager; import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
...@@ -160,13 +161,13 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { ...@@ -160,13 +161,13 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) { if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) {
packages = AutoConfigurationPackages.get(this.beanFactory); packages = AutoConfigurationPackages.get(this.beanFactory);
} }
return packages.toArray(new String[packages.size()]); return StringUtils.toStringArray(packages);
} }
private String[] getMappingResources() { private String[] getMappingResources() {
List<String> mappingResources = this.properties.getMappingResources(); List<String> mappingResources = this.properties.getMappingResources();
return (!ObjectUtils.isEmpty(mappingResources) return (!ObjectUtils.isEmpty(mappingResources)
? mappingResources.toArray(new String[mappingResources.size()]) : null); ? StringUtils.toStringArray(mappingResources) : null);
} }
/** /**
......
...@@ -29,6 +29,7 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio ...@@ -29,6 +29,7 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
import org.springframework.security.oauth2.client.registration.ClientRegistration.Builder; import org.springframework.security.oauth2.client.registration.ClientRegistration.Builder;
import org.springframework.security.oauth2.core.AuthorizationGrantType; import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod; import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
import org.springframework.util.StringUtils;
/** /**
* Adapter class to convert {@link OAuth2ClientProperties} to a * Adapter class to convert {@link OAuth2ClientProperties} to a
...@@ -63,8 +64,7 @@ final class OAuth2ClientPropertiesRegistrationAdapter { ...@@ -63,8 +64,7 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new) map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new)
.to(builder::authorizationGrantType); .to(builder::authorizationGrantType);
map.from(properties::getRedirectUriTemplate).to(builder::redirectUriTemplate); map.from(properties::getRedirectUriTemplate).to(builder::redirectUriTemplate);
map.from(properties::getScope) map.from(properties::getScope).as((scope) -> StringUtils.toStringArray(scope))
.as((scope) -> scope.toArray(new String[scope.size()]))
.to(builder::scope); .to(builder::scope);
map.from(properties::getClientName).to(builder::clientName); map.from(properties::getClientName).to(builder::clientName);
return builder.build(); return builder.build();
......
...@@ -35,6 +35,7 @@ import org.springframework.security.core.userdetails.ReactiveUserDetailsService; ...@@ -35,6 +35,7 @@ import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.StringUtils;
/** /**
* Default user {@link Configuration} for a reactive web application. Configures a * Default user {@link Configuration} for a reactive web application. Configures a
...@@ -72,7 +73,7 @@ public class ReactiveUserDetailsServiceAutoConfiguration { ...@@ -72,7 +73,7 @@ public class ReactiveUserDetailsServiceAutoConfiguration {
private UserDetails getUserDetails(SecurityProperties.User user, String password) { private UserDetails getUserDetails(SecurityProperties.User user, String password) {
List<String> roles = user.getRoles(); List<String> roles = user.getRoles();
return User.withUsername(user.getName()).password(password) return User.withUsername(user.getName()).password(password)
.roles(roles.toArray(new String[roles.size()])).build(); .roles(StringUtils.toStringArray(roles)).build();
} }
private String getOrDeducePassword(SecurityProperties.User user, private String getOrDeducePassword(SecurityProperties.User user,
......
...@@ -36,6 +36,7 @@ import org.springframework.security.core.userdetails.User; ...@@ -36,6 +36,7 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.util.StringUtils;
/** /**
* Configuration for a Spring Security in-memory {@link AuthenticationManager}. Adds an * Configuration for a Spring Security in-memory {@link AuthenticationManager}. Adds an
...@@ -71,7 +72,7 @@ public class UserDetailsServiceAutoConfiguration { ...@@ -71,7 +72,7 @@ public class UserDetailsServiceAutoConfiguration {
List<String> roles = user.getRoles(); List<String> roles = user.getRoles();
return new InMemoryUserDetailsManager(User.withUsername(user.getName()) return new InMemoryUserDetailsManager(User.withUsername(user.getName())
.password(getOrDeducePassword(user, passwordEncoder.getIfAvailable())) .password(getOrDeducePassword(user, passwordEncoder.getIfAvailable()))
.roles(roles.toArray(new String[roles.size()])).build()); .roles(StringUtils.toStringArray(roles)).build());
} }
public String getOrDeducePassword(SecurityProperties.User user, public String getOrDeducePassword(SecurityProperties.User user,
......
...@@ -48,6 +48,7 @@ import org.springframework.core.type.AnnotationMetadata; ...@@ -48,6 +48,7 @@ import org.springframework.core.type.AnnotationMetadata;
import org.springframework.session.ReactiveSessionRepository; import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session; import org.springframework.session.Session;
import org.springframework.session.SessionRepository; import org.springframework.session.SessionRepository;
import org.springframework.util.StringUtils;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Session. * {@link EnableAutoConfiguration Auto-configuration} for Spring Session.
...@@ -113,7 +114,7 @@ public class SessionAutoConfiguration { ...@@ -113,7 +114,7 @@ public class SessionAutoConfiguration {
imports.add(SessionStoreMappings.getConfigurationClass(webApplicationType, imports.add(SessionStoreMappings.getConfigurationClass(webApplicationType,
types[i])); types[i]));
} }
return imports.toArray(new String[imports.size()]); return StringUtils.toStringArray(imports);
} }
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector; ...@@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -92,7 +93,7 @@ public class CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests { ...@@ -92,7 +93,7 @@ public class CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests {
CouchbaseReactiveRepositoriesAutoConfiguration.class }) { CouchbaseReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName()); names.add(type.getName());
} }
return names.toArray(new String[0]); return StringUtils.toStringArray(names);
} }
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -41,6 +41,7 @@ import org.springframework.context.annotation.ImportSelector; ...@@ -41,6 +41,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -164,7 +165,7 @@ public class MixedMongoRepositoriesAutoConfigurationTests { ...@@ -164,7 +165,7 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
MongoRepositoriesAutoConfiguration.class }) { MongoRepositoriesAutoConfiguration.class }) {
names.add(type.getName()); names.add(type.getName());
} }
return names.toArray(new String[0]); return StringUtils.toStringArray(names);
} }
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector; ...@@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -93,7 +94,7 @@ public class MongoReactiveAndBlockingRepositoriesAutoConfigurationTests { ...@@ -93,7 +94,7 @@ public class MongoReactiveAndBlockingRepositoriesAutoConfigurationTests {
MongoReactiveRepositoriesAutoConfiguration.class }) { MongoReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName()); names.add(type.getName());
} }
return names.toArray(new String[0]); return StringUtils.toStringArray(names);
} }
} }
......
...@@ -47,6 +47,7 @@ import org.springframework.context.annotation.Bean; ...@@ -47,6 +47,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource; import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -226,7 +227,7 @@ public class DataSourceAutoConfigurationTests { ...@@ -226,7 +227,7 @@ public class DataSourceAutoConfigurationTests {
private <T extends DataSource> void assertDataSource(Class<T> expectedType, private <T extends DataSource> void assertDataSource(Class<T> expectedType,
List<String> hiddenPackages, Consumer<T> consumer) { List<String> hiddenPackages, Consumer<T> consumer) {
FilteredClassLoader classLoader = new FilteredClassLoader( FilteredClassLoader classLoader = new FilteredClassLoader(
hiddenPackages.toArray(new String[hiddenPackages.size()])); StringUtils.toStringArray(hiddenPackages));
this.contextRunner.withClassLoader(classLoader).run((context) -> { this.contextRunner.withClassLoader(classLoader).run((context) -> {
DataSource bean = context.getBean(DataSource.class); DataSource bean = context.getBean(DataSource.class);
assertThat(bean).isInstanceOf(expectedType); assertThat(bean).isInstanceOf(expectedType);
......
...@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration; ...@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -89,8 +90,9 @@ public class ActiveMQAutoConfigurationTests { ...@@ -89,8 +90,9 @@ public class ActiveMQAutoConfigurationTests {
.isEqualTo(defaultFactory.getSendTimeout()); .isEqualTo(defaultFactory.getSendTimeout());
assertThat(connectionFactory.isTrustAllPackages()) assertThat(connectionFactory.isTrustAllPackages())
.isEqualTo(defaultFactory.isTrustAllPackages()); .isEqualTo(defaultFactory.isTrustAllPackages());
assertThat(connectionFactory.getTrustedPackages()).containsExactly( assertThat(connectionFactory.getTrustedPackages())
defaultFactory.getTrustedPackages().toArray(new String[] {})); .containsExactly(StringUtils
.toStringArray(defaultFactory.getTrustedPackages()));
}); });
} }
...@@ -113,8 +115,7 @@ public class ActiveMQAutoConfigurationTests { ...@@ -113,8 +115,7 @@ public class ActiveMQAutoConfigurationTests {
assertThat(connectionFactory.getUserName()).isEqualTo("foo"); assertThat(connectionFactory.getUserName()).isEqualTo("foo");
assertThat(connectionFactory.getPassword()).isEqualTo("bar"); assertThat(connectionFactory.getPassword()).isEqualTo("bar");
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500); assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
assertThat(connectionFactory.isNonBlockingRedelivery()) assertThat(connectionFactory.isNonBlockingRedelivery()).isTrue();
.isTrue();
assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000); assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000);
assertThat(connectionFactory.isTrustAllPackages()).isFalse(); assertThat(connectionFactory.isTrustAllPackages()).isFalse();
assertThat(connectionFactory.getTrustedPackages()) assertThat(connectionFactory.getTrustedPackages())
...@@ -177,23 +178,19 @@ public class ActiveMQAutoConfigurationTests { ...@@ -177,23 +178,19 @@ public class ActiveMQAutoConfigurationTests {
.hasSize(1); .hasSize(1);
PooledConnectionFactory connectionFactory = context PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class); .getBean(PooledConnectionFactory.class);
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()) assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
.isFalse();
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout()) assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout())
.isEqualTo(64); .isEqualTo(64);
assertThat(connectionFactory.isCreateConnectionOnStartup()) assertThat(connectionFactory.isCreateConnectionOnStartup()).isFalse();
.isFalse();
assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096); assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096);
assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512); assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512);
assertThat(connectionFactory.getMaxConnections()).isEqualTo(256); assertThat(connectionFactory.getMaxConnections()).isEqualTo(256);
assertThat(connectionFactory.getMaximumActiveSessionPerConnection()) assertThat(connectionFactory.getMaximumActiveSessionPerConnection())
.isEqualTo(1024); .isEqualTo(1024);
assertThat(connectionFactory.isReconnectOnException()) assertThat(connectionFactory.isReconnectOnException()).isFalse();
.isFalse();
assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis()) assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis())
.isEqualTo(2048); .isEqualTo(2048);
assertThat(connectionFactory.isUseAnonymousProducers()) assertThat(connectionFactory.isUseAnonymousProducers()).isFalse();
.isFalse();
}); });
} }
......
...@@ -51,6 +51,7 @@ import org.springframework.http.HttpStatus; ...@@ -51,6 +51,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity; import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -228,7 +229,7 @@ public class BasicErrorControllerIntegrationTests { ...@@ -228,7 +229,7 @@ public class BasicErrorControllerIntegrationTests {
args.addAll(Arrays.asList(arguments)); args.addAll(Arrays.asList(arguments));
} }
this.context = SpringApplication.run(TestConfiguration.class, this.context = SpringApplication.run(TestConfiguration.class,
args.toArray(new String[args.size()])); StringUtils.toStringArray(args));
} }
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -96,7 +96,7 @@ public final class SpringCli { ...@@ -96,7 +96,7 @@ public final class SpringCli {
} }
} }
} }
return urls.toArray(new URL[urls.size()]); return urls.toArray(new URL[0]);
} }
} }
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -195,7 +195,7 @@ public class CommandRunner implements Iterable<Command> { ...@@ -195,7 +195,7 @@ public class CommandRunner implements Iterable<Command> {
} }
rtn.add(arg); rtn.add(arg);
} }
return rtn.toArray(new String[rtn.size()]); return StringUtils.toStringArray(rtn);
} }
/** /**
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,6 +25,7 @@ import joptsimple.OptionSet; ...@@ -25,6 +25,7 @@ import joptsimple.OptionSet;
import org.springframework.boot.cli.util.ResourceUtils; import org.springframework.boot.cli.util.ResourceUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* Extract source file options (anything following '--' in an {@link OptionSet}). * Extract source file options (anything following '--' in an {@link OptionSet}).
...@@ -125,7 +126,11 @@ public class SourceOptions { ...@@ -125,7 +126,11 @@ public class SourceOptions {
} }
public String[] getArgsArray() { public String[] getArgsArray() {
return this.args.toArray(new String[this.args.size()]); return this.args.stream().map(this::asString).toArray(String[]::new);
}
private String asString(Object arg) {
return (arg == null ? null : String.valueOf(arg));
} }
public List<String> getSources() { public List<String> getSources() {
...@@ -133,7 +138,7 @@ public class SourceOptions { ...@@ -133,7 +138,7 @@ public class SourceOptions {
} }
public String[] getSourcesArray() { public String[] getSourcesArray() {
return this.sources.toArray(new String[this.sources.size()]); return StringUtils.toStringArray(this.sources);
} }
} }
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.AbstractCommand; ...@@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.AbstractCommand;
import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.status.ExitStatus; import org.springframework.boot.cli.command.status.ExitStatus;
import org.springframework.boot.loader.tools.RunProcess; import org.springframework.boot.loader.tools.RunProcess;
import org.springframework.util.StringUtils;
/** /**
* Special {@link Command} used to run a process from the shell. NOTE: this command is not * Special {@link Command} used to run a process from the shell. NOTE: this command is not
...@@ -49,7 +50,7 @@ class RunProcessCommand extends AbstractCommand { ...@@ -49,7 +50,7 @@ class RunProcessCommand extends AbstractCommand {
protected ExitStatus run(Collection<String> args) throws IOException { protected ExitStatus run(Collection<String> args) throws IOException {
this.process = new RunProcess(this.command); this.process = new RunProcess(this.command);
int code = this.process.run(true, args.toArray(new String[args.size()])); int code = this.process.run(true, StringUtils.toStringArray(args));
if (code == 0) { if (code == 0) {
return ExitStatus.OK; return ExitStatus.OK;
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -169,7 +169,7 @@ public class DependencyManagementBomTransformation ...@@ -169,7 +169,7 @@ public class DependencyManagementBomTransformation
private void updateDependencyResolutionContext( private void updateDependencyResolutionContext(
List<Map<String, String>> bomDependencies) { List<Map<String, String>> bomDependencies) {
URI[] uris = Grape.getInstance().resolve(null, URI[] uris = Grape.getInstance().resolve(null,
bomDependencies.toArray(new Map[bomDependencies.size()])); bomDependencies.toArray(new Map[0]));
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance(); DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
for (URI uri : uris) { for (URI uri : uris) {
try { try {
......
...@@ -186,7 +186,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader { ...@@ -186,7 +186,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
findGroovyJarsFromClassPath(urls); findGroovyJarsFromClassPath(urls);
} }
Assert.state(!urls.isEmpty(), "Unable to find groovy JAR"); Assert.state(!urls.isEmpty(), "Unable to find groovy JAR");
return new ArrayList<>(urls).toArray(new URL[urls.size()]); return new ArrayList<>(urls).toArray(new URL[0]);
} }
private void findGroovyJarsDirectly(ClassLoader classLoader, Set<URL> urls) { private void findGroovyJarsDirectly(ClassLoader classLoader, Set<URL> urls) {
......
...@@ -49,6 +49,7 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; ...@@ -49,6 +49,7 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext;
import org.springframework.boot.cli.compiler.grape.GrapeEngineInstaller; import org.springframework.boot.cli.compiler.grape.GrapeEngineInstaller;
import org.springframework.boot.cli.util.ResourceUtils; import org.springframework.boot.cli.util.ResourceUtils;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.ClassUtils;
/** /**
* Compiler for Groovy sources. Primarily a simple Facade for * Compiler for Groovy sources. Primarily a simple Facade for
...@@ -220,7 +221,7 @@ public class GroovyCompiler { ...@@ -220,7 +221,7 @@ public class GroovyCompiler {
classes.add(0, mainClass); classes.add(0, mainClass);
} }
return classes.toArray(new Class<?>[classes.size()]); return ClassUtils.toClassArray(classes);
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
......
...@@ -290,7 +290,7 @@ public class AetherGrapeEngine implements GrapeEngine { ...@@ -290,7 +290,7 @@ public class AetherGrapeEngine implements GrapeEngine {
for (File file : files) { for (File file : files) {
uris.add(file.toURI()); uris.add(file.toURI());
} }
return uris.toArray(new URI[uris.size()]); return uris.toArray(new URI[0]);
} }
catch (Exception ex) { catch (Exception ex) {
throw new DependencyResolutionFailedException(ex); throw new DependencyResolutionFailedException(ex);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -43,6 +43,7 @@ import org.springframework.boot.cli.command.grab.GrabCommand; ...@@ -43,6 +43,7 @@ import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.boot.cli.command.run.RunCommand; import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
/** /**
* {@link TestRule} that can be used to invoke CLI commands. * {@link TestRule} that can be used to invoke CLI commands.
...@@ -84,7 +85,7 @@ public class CliTester implements TestRule { ...@@ -84,7 +85,7 @@ public class CliTester implements TestRule {
"--classpath=.:" + new File("target/test-classes").getAbsolutePath()); "--classpath=.:" + new File("target/test-classes").getAbsolutePath());
} }
Future<RunCommand> future = submitCommand(new RunCommand(), Future<RunCommand> future = submitCommand(new RunCommand(),
updatedArgs.toArray(new String[updatedArgs.size()])); StringUtils.toStringArray(updatedArgs));
this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS)); this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));
return getOutput(); return getOutput();
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -122,7 +122,7 @@ public class DevToolsProperties { ...@@ -122,7 +122,7 @@ public class DevToolsProperties {
allExclude.addAll( allExclude.addAll(
StringUtils.commaDelimitedListToSet(this.additionalExclude)); StringUtils.commaDelimitedListToSet(this.additionalExclude));
} }
return allExclude.toArray(new String[allExclude.size()]); return StringUtils.toStringArray(allExclude);
} }
public String getExclude() { public String getExclude() {
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -79,7 +79,7 @@ final class ChangeableUrls implements Iterable<URL> { ...@@ -79,7 +79,7 @@ final class ChangeableUrls implements Iterable<URL> {
} }
public URL[] toArray() { public URL[] toArray() {
return this.urls.toArray(new URL[this.urls.size()]); return this.urls.toArray(new URL[0]);
} }
public List<URL> toList() { public List<URL> toList() {
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -119,7 +119,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe ...@@ -119,7 +119,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
} }
} }
resources.addAll(getAdditionalResources(locationPattern)); resources.addAll(getAdditionalResources(locationPattern));
return resources.toArray(new Resource[resources.size()]); return resources.toArray(new Resource[0]);
} }
private List<Resource> getAdditionalResources(String locationPattern) private List<Resource> getAdditionalResources(String locationPattern)
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -273,7 +273,7 @@ public class Restarter { ...@@ -273,7 +273,7 @@ public class Restarter {
private Throwable doStart() throws Exception { private Throwable doStart() throws Exception {
Assert.notNull(this.mainClassName, "Unable to find the main class to restart"); Assert.notNull(this.mainClassName, "Unable to find the main class to restart");
URL[] urls = this.urls.toArray(new URL[this.urls.size()]); URL[] urls = this.urls.toArray(new URL[0]);
ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles); ClassLoaderFiles updatedFiles = new ClassLoaderFiles(this.classLoaderFiles);
ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader, ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader,
urls, updatedFiles, this.logger); urls, updatedFiles, this.logger);
......
...@@ -41,6 +41,7 @@ import org.springframework.test.web.servlet.result.PrintingResultHandler; ...@@ -41,6 +41,7 @@ import org.springframework.test.web.servlet.result.PrintingResultHandler;
import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder; import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
/** /**
...@@ -133,7 +134,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi ...@@ -133,7 +134,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
builder.addFilters(filter); builder.addFilters(filter);
} }
else { else {
builder.addFilter(filter, urls.toArray(new String[urls.size()])); builder.addFilter(filter, StringUtils.toStringArray(urls));
} }
} }
......
...@@ -173,7 +173,7 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -173,7 +173,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) { if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) {
properties.add("server.port=-1"); properties.add("server.port=-1");
} }
return properties.toArray(new String[properties.size()]); return StringUtils.toStringArray(properties);
} }
private void disableJmx(List<String> properties) { private void disableJmx(List<String> properties) {
...@@ -187,9 +187,8 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -187,9 +187,8 @@ public class SpringBootContextLoader extends AbstractContextLoader {
private ConfigurationPropertySource convertToConfigurationPropertySource( private ConfigurationPropertySource convertToConfigurationPropertySource(
List<String> properties) { List<String> properties) {
String[] array = properties.toArray(new String[properties.size()]); return new MapConfigurationPropertySource(TestPropertySourceUtils
return new MapConfigurationPropertySource( .convertInlinedPropertiesToMap(StringUtils.toStringArray(properties)));
TestPropertySourceUtils.convertInlinedPropertiesToMap(array));
} }
/** /**
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -52,6 +52,7 @@ import org.springframework.test.context.web.WebMergedContextConfiguration; ...@@ -52,6 +52,7 @@ import org.springframework.test.context.web.WebMergedContextConfiguration;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* {@link TestContextBootstrapper} for Spring Boot. Provides support for * {@link TestContextBootstrapper} for Spring Boot. Provides support for
...@@ -137,7 +138,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr ...@@ -137,7 +138,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
if (configAttributes.getClasses() != null) { if (configAttributes.getClasses() != null) {
combined.addAll(Arrays.asList(configAttributes.getClasses())); combined.addAll(Arrays.asList(configAttributes.getClasses()));
} }
configAttributes.setClasses(combined.toArray(new Class<?>[combined.size()])); configAttributes.setClasses(ClassUtils.toClassArray(combined));
} }
@Override @Override
...@@ -153,8 +154,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr ...@@ -153,8 +154,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
List<String> propertySourceProperties = getAndProcessPropertySourceProperties( List<String> propertySourceProperties = getAndProcessPropertySourceProperties(
mergedConfig); mergedConfig);
mergedConfig = createModifiedConfig(mergedConfig, classes, mergedConfig = createModifiedConfig(mergedConfig, classes,
propertySourceProperties StringUtils.toStringArray(propertySourceProperties));
.toArray(new String[propertySourceProperties.size()]));
WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass()); WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass());
if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) { if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) {
WebApplicationType webApplicationType = getWebApplicationType(mergedConfig); WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -28,6 +28,7 @@ import org.mockito.Mockito; ...@@ -28,6 +28,7 @@ import org.mockito.Mockito;
import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -147,7 +148,7 @@ class MockDefinition extends Definition { ...@@ -147,7 +148,7 @@ class MockDefinition extends Definition {
settings.name(name); settings.name(name);
} }
if (!this.extraInterfaces.isEmpty()) { if (!this.extraInterfaces.isEmpty()) {
settings.extraInterfaces(this.extraInterfaces.toArray(new Class<?>[] {})); settings.extraInterfaces(ClassUtils.toClassArray(this.extraInterfaces));
} }
settings.defaultAnswer(this.answer); settings.defaultAnswer(this.answer);
if (this.serializable) { if (this.serializable) {
......
...@@ -279,7 +279,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda ...@@ -279,7 +279,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
} }
} }
beans.removeIf(this::isScopedTarget); beans.removeIf(this::isScopedTarget);
return beans.toArray(new String[beans.size()]); return StringUtils.toStringArray(beans);
} }
private boolean isScopedTarget(String beanName) { private boolean isScopedTarget(String beanName) {
......
...@@ -123,7 +123,7 @@ public class TestJarFile { ...@@ -123,7 +123,7 @@ public class TestJarFile {
public File getFile(String extension) throws IOException { public File getFile(String extension) throws IOException {
File file = this.temporaryFolder.newFile(); File file = this.temporaryFolder.newFile();
file = new File(file.getParent(), file.getName() + "." + extension); file = new File(file.getParent(), file.getName() + "." + extension);
ZipUtil.pack(this.entries.toArray(new ZipEntrySource[this.entries.size()]), file); ZipUtil.pack(this.entries.toArray(new ZipEntrySource[0]), file);
return file; return file;
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -61,7 +61,7 @@ public abstract class Launcher { ...@@ -61,7 +61,7 @@ public abstract class Launcher {
for (Archive archive : archives) { for (Archive archive : archives) {
urls.add(archive.getUrl()); urls.add(archive.getUrl());
} }
return createClassLoader(urls.toArray(new URL[urls.size()])); return createClassLoader(urls.toArray(new URL[0]));
} }
/** /**
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -369,7 +369,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo { ...@@ -369,7 +369,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
addResources(urls); addResources(urls);
addProjectClasses(urls); addProjectClasses(urls);
addDependencies(urls); addDependencies(urls);
return urls.toArray(new URL[urls.size()]); return urls.toArray(new URL[0]);
} }
catch (IOException ex) { catch (IOException ex) {
throw new MojoExecutionException("Unable to build classpath", ex); throw new MojoExecutionException("Unable to build classpath", ex);
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -262,7 +262,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { ...@@ -262,7 +262,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
if (!this.includeSystemScope) { if (!this.includeSystemScope) {
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM)); filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
} }
return filters.toArray(new ArtifactsFilter[filters.size()]); return filters.toArray(new ArtifactsFilter[0]);
} }
private LaunchScript getLaunchScript() throws IOException { private LaunchScript getLaunchScript() throws IOException {
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -49,7 +49,7 @@ class RunArguments { ...@@ -49,7 +49,7 @@ class RunArguments {
} }
public String[] asArray() { public String[] asArray() {
return this.args.toArray(new String[this.args.size()]); return this.args.toArray(new String[0]);
} }
private static String[] parseArgs(String arguments) { private static String[] parseArgs(String arguments) {
......
...@@ -71,7 +71,7 @@ public class RunMojo extends AbstractRunMojo { ...@@ -71,7 +71,7 @@ public class RunMojo extends AbstractRunMojo {
new JavaExecutable().toString()); new JavaExecutable().toString());
Runtime.getRuntime() Runtime.getRuntime()
.addShutdownHook(new Thread(new RunProcessKiller(runProcess))); .addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
int exitCode = runProcess.run(true, args.toArray(new String[args.size()])); int exitCode = runProcess.run(true, args.toArray(new String[0]));
if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) { if (exitCode == 0 || exitCode == EXIT_CODE_SIGINT) {
return; return;
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -105,7 +105,7 @@ public class StartMojo extends AbstractRunMojo { ...@@ -105,7 +105,7 @@ public class StartMojo extends AbstractRunMojo {
try { try {
RunProcess runProcess = new RunProcess(workingDirectory, RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString()); new JavaExecutable().toString());
runProcess.run(false, args.toArray(new String[args.size()])); runProcess.run(false, args.toArray(new String[0]));
return runProcess; return runProcess;
} }
catch (Exception ex) { catch (Exception ex) {
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -105,7 +105,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner { ...@@ -105,7 +105,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
extractedUrls.add(url); extractedUrls.add(url);
} }
}); });
return extractedUrls.toArray(new URL[extractedUrls.size()]); return extractedUrls.toArray(new URL[0]);
} }
private Stream<URL> doExtractUrls(ClassLoader classLoader) throws Exception { private Stream<URL> doExtractUrls(ClassLoader classLoader) throws Exception {
...@@ -158,7 +158,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner { ...@@ -158,7 +158,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
processedUrls.add(url); processedUrls.add(url);
} }
} }
return processedUrls.toArray(new URL[processedUrls.size()]); return processedUrls.toArray(new URL[0]);
} }
private List<URL> getAdditionalUrls(Class<?> testClass) throws Exception { private List<URL> getAdditionalUrls(Class<?> testClass) throws Exception {
......
...@@ -380,7 +380,7 @@ public class SpringApplication { ...@@ -380,7 +380,7 @@ public class SpringApplication {
// Load the sources // Load the sources
Set<Object> sources = getAllSources(); Set<Object> sources = getAllSources();
Assert.notEmpty(sources, "Sources must not be empty"); Assert.notEmpty(sources, "Sources must not be empty");
load(context, sources.toArray(new Object[sources.size()])); load(context, sources.toArray(new Object[0]));
listeners.contextLoaded(context); listeners.contextLoaded(context);
} }
...@@ -516,7 +516,7 @@ public class SpringApplication { ...@@ -516,7 +516,7 @@ public class SpringApplication {
// But these ones should go first (last wins in a property key clash) // But these ones should go first (last wins in a property key clash)
Set<String> profiles = new LinkedHashSet<>(this.additionalProfiles); Set<String> profiles = new LinkedHashSet<>(this.additionalProfiles);
profiles.addAll(Arrays.asList(environment.getActiveProfiles())); profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
environment.setActiveProfiles(profiles.toArray(new String[profiles.size()])); environment.setActiveProfiles(StringUtils.toStringArray(profiles));
} }
private void configureIgnoreBeanInfo(ConfigurableEnvironment environment) { private void configureIgnoreBeanInfo(ConfigurableEnvironment environment) {
......
...@@ -37,6 +37,7 @@ import org.springframework.context.ApplicationListener; ...@@ -37,6 +37,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
/** /**
* Builder for {@link SpringApplication} and {@link ApplicationContext} instances with * Builder for {@link SpringApplication} and {@link ApplicationContext} instances with
...@@ -455,16 +456,16 @@ public class SpringApplicationBuilder { ...@@ -455,16 +456,16 @@ public class SpringApplicationBuilder {
*/ */
public SpringApplicationBuilder profiles(String... profiles) { public SpringApplicationBuilder profiles(String... profiles) {
this.additionalProfiles.addAll(Arrays.asList(profiles)); this.additionalProfiles.addAll(Arrays.asList(profiles));
this.application.setAdditionalProfiles(this.additionalProfiles this.application.setAdditionalProfiles(
.toArray(new String[this.additionalProfiles.size()])); StringUtils.toStringArray(this.additionalProfiles));
return this; return this;
} }
private SpringApplicationBuilder additionalProfiles( private SpringApplicationBuilder additionalProfiles(
Collection<String> additionalProfiles) { Collection<String> additionalProfiles) {
this.additionalProfiles = new LinkedHashSet<>(additionalProfiles); this.additionalProfiles = new LinkedHashSet<>(additionalProfiles);
this.application.setAdditionalProfiles(this.additionalProfiles this.application.setAdditionalProfiles(
.toArray(new String[this.additionalProfiles.size()])); StringUtils.toStringArray(this.additionalProfiles));
return this; return this;
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -26,6 +26,7 @@ import java.util.LinkedList; ...@@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -34,6 +35,7 @@ import org.springframework.core.OrderComparator; ...@@ -34,6 +35,7 @@ import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/** /**
* A set of {@link Configuration @Configuration} classes that can be registered in * A set of {@link Configuration @Configuration} classes that can be registered in
...@@ -114,12 +116,17 @@ public abstract class Configurations { ...@@ -114,12 +116,17 @@ public abstract class Configurations {
* @return configuration classes in registration order * @return configuration classes in registration order
*/ */
public static Class<?>[] getClasses(Collection<Configurations> configurations) { public static Class<?>[] getClasses(Collection<Configurations> configurations) {
List<Configurations> orderedConfigurations = new ArrayList<>(configurations); List<Configurations> ordered = new ArrayList<>(configurations);
orderedConfigurations.sort(COMPARATOR); ordered.sort(COMPARATOR);
List<Configurations> collated = collate(orderedConfigurations); List<Configurations> collated = collate(ordered);
return collated.stream().flatMap((c) -> c.getClasses().stream()) LinkedHashSet<Class<?>> classes = collated.stream()
.collect(Collectors.toCollection(LinkedHashSet::new)) .flatMap(Configurations::streamClasses)
.toArray(new Class<?>[0]); .collect(Collectors.toCollection(LinkedHashSet::new));
return ClassUtils.toClassArray(classes);
}
private static Stream<Class<?>> streamClasses(Configurations configurations) {
return configurations.getClasses().stream();
} }
private static List<Configurations> collate( private static List<Configurations> collate(
......
...@@ -565,7 +565,7 @@ public class ConfigFileApplicationListener ...@@ -565,7 +565,7 @@ public class ConfigFileApplicationListener
// But this one should go first (last wins in a property key clash) // But this one should go first (last wins in a property key clash)
profiles.add(profile.getName()); profiles.add(profile.getName());
profiles.addAll(Arrays.asList(environment.getActiveProfiles())); profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
environment.setActiveProfiles(profiles.toArray(new String[profiles.size()])); environment.setActiveProfiles(StringUtils.toStringArray(profiles));
} }
private Set<String> getSearchLocations() { private Set<String> getSearchLocations() {
......
...@@ -113,7 +113,7 @@ class ConfigurationPropertiesBinder { ...@@ -113,7 +113,7 @@ class ConfigurationPropertiesBinder {
} }
if (!validators.isEmpty()) { if (!validators.isEmpty()) {
handler = new ValidationBindHandler(handler, handler = new ValidationBindHandler(handler,
validators.toArray(new Validator[validators.size()])); validators.toArray(new Validator[0]));
} }
return handler; return handler;
} }
......
...@@ -460,8 +460,7 @@ public final class ConfigurationPropertyName ...@@ -460,8 +460,7 @@ public final class ConfigurationPropertyName
elements.add(elementValue); elements.add(elementValue);
} }
}); });
return new ConfigurationPropertyName( return new ConfigurationPropertyName(elements.toArray(new CharSequence[0]));
elements.toArray(new CharSequence[elements.size()]));
} }
/** /**
...@@ -508,8 +507,7 @@ public final class ConfigurationPropertyName ...@@ -508,8 +507,7 @@ public final class ConfigurationPropertyName
elements.add(elementValue); elements.add(elementValue);
} }
}); });
return new ConfigurationPropertyName( return new ConfigurationPropertyName(elements.toArray(new CharSequence[0]));
elements.toArray(new CharSequence[elements.size()]));
} }
private static void process(CharSequence name, char separator, private static void process(CharSequence name, char separator,
......
...@@ -121,7 +121,7 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope ...@@ -121,7 +121,7 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
mappings.add(mapping); mappings.add(mapping);
} }
} }
result = mappings.toArray(new PropertyMapping[mappings.size()]); result = mappings.toArray(new PropertyMapping[0]);
if (cache != null) { if (cache != null) {
cache.setMappings(result); cache.setMappings(result);
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.BeanDefinition; ...@@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.util.StringUtils;
/** /**
* {@link BeanFactoryPostProcessor} to automatically setup the recommended * {@link BeanFactoryPostProcessor} to automatically setup the recommended
...@@ -65,7 +66,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor ...@@ -65,7 +66,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor
addDependencies(beanFactory, "javax.jms.ConnectionFactory", dependsOn); addDependencies(beanFactory, "javax.jms.ConnectionFactory", dependsOn);
addDependencies(beanFactory, "javax.sql.DataSource", dependsOn); addDependencies(beanFactory, "javax.sql.DataSource", dependsOn);
if (dependsOn.size() != initialSize) { if (dependsOn.size() != initialSize) {
bean.setDependsOn(dependsOn.toArray(new String[dependsOn.size()])); bean.setDependsOn(StringUtils.toStringArray(dependsOn));
} }
} }
...@@ -77,7 +78,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor ...@@ -77,7 +78,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor
BeanDefinition bean = beanFactory.getBeanDefinition(messageDrivenContainer); BeanDefinition bean = beanFactory.getBeanDefinition(messageDrivenContainer);
Set<String> dependsOn = new LinkedHashSet<>(asList(bean.getDependsOn())); Set<String> dependsOn = new LinkedHashSet<>(asList(bean.getDependsOn()));
dependsOn.addAll(asList(transactionManagers)); dependsOn.addAll(asList(transactionManagers));
bean.setDependsOn(dependsOn.toArray(new String[dependsOn.size()])); bean.setDependsOn(StringUtils.toStringArray(dependsOn));
} }
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -119,8 +119,7 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { ...@@ -119,8 +119,7 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
Collections.addAll(supportedConfigLocations, "log4j2.json", "log4j2.jsn"); Collections.addAll(supportedConfigLocations, "log4j2.json", "log4j2.jsn");
} }
supportedConfigLocations.add("log4j2.xml"); supportedConfigLocations.add("log4j2.xml");
return supportedConfigLocations return StringUtils.toStringArray(supportedConfigLocations);
.toArray(new String[supportedConfigLocations.size()]);
} }
protected boolean isClassAvailable(String className) { protected boolean isClassAvailable(String className) {
......
...@@ -30,6 +30,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; ...@@ -30,6 +30,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* Convenient builder for JPA EntityManagerFactory instances. Collects common * Convenient builder for JPA EntityManagerFactory instances. Collects common
...@@ -142,7 +143,7 @@ public class EntityManagerFactoryBuilder { ...@@ -142,7 +143,7 @@ public class EntityManagerFactoryBuilder {
for (Class<?> type : basePackageClasses) { for (Class<?> type : basePackageClasses) {
packages.add(ClassUtils.getPackageName(type)); packages.add(ClassUtils.getPackageName(type));
} }
this.packagesToScan = packages.toArray(new String[0]); this.packagesToScan = StringUtils.toStringArray(packages);
return this; return this;
} }
......
...@@ -277,8 +277,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor ...@@ -277,8 +277,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
resources.add(resource); resources.add(resource);
} }
} }
handler.setBaseResource(new ResourceCollection( handler.setBaseResource(
resources.toArray(new Resource[resources.size()]))); new ResourceCollection(resources.toArray(new Resource[0])));
} }
catch (Exception ex) { catch (Exception ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
...@@ -343,7 +343,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor ...@@ -343,7 +343,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
configurations.addAll(getConfigurations()); configurations.addAll(getConfigurations());
configurations.add(getErrorPageConfiguration()); configurations.add(getErrorPageConfiguration());
configurations.add(getMimeTypeConfiguration()); configurations.add(getMimeTypeConfiguration());
return configurations.toArray(new Configuration[configurations.size()]); return configurations.toArray(new Configuration[0]);
} }
/** /**
......
...@@ -74,7 +74,7 @@ final class UndertowCompressionConfigurer { ...@@ -74,7 +74,7 @@ final class UndertowCompressionConfigurer {
predicates.add(Predicates.not(Predicates.regex(agentHeader, agent))); predicates.add(Predicates.not(Predicates.regex(agentHeader, agent)));
} }
} }
return predicates.toArray(new Predicate[predicates.size()]); return predicates.toArray(new Predicate[0]);
} }
private static class CompressibleMimeTypePredicate implements Predicate { private static class CompressibleMimeTypePredicate implements Predicate {
......
...@@ -387,7 +387,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac ...@@ -387,7 +387,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
} }
resourceManagers.add(new MetaInfResourcesResourceManager(resourceJarUrls)); resourceManagers.add(new MetaInfResourcesResourceManager(resourceJarUrls));
return new CompositeResourceManager( return new CompositeResourceManager(
resourceManagers.toArray(new ResourceManager[resourceManagers.size()])); resourceManagers.toArray(new ResourceManager[0]));
} }
private File getCanonicalDocumentRoot(File docBase) { private File getCanonicalDocumentRoot(File docBase) {
......
...@@ -233,8 +233,7 @@ public class AnnotationConfigReactiveWebApplicationContext ...@@ -233,8 +233,7 @@ public class AnnotationConfigReactiveWebApplicationContext
+ StringUtils.collectionToCommaDelimitedString(this.annotatedClasses) + StringUtils.collectionToCommaDelimitedString(this.annotatedClasses)
+ "]"); + "]");
} }
reader.register(this.annotatedClasses reader.register(ClassUtils.toClassArray(this.annotatedClasses));
.toArray(new Class<?>[this.annotatedClasses.size()]));
} }
private void scanBasePackages(ClassPathBeanDefinitionScanner scanner) { private void scanBasePackages(ClassPathBeanDefinitionScanner scanner) {
...@@ -243,7 +242,7 @@ public class AnnotationConfigReactiveWebApplicationContext ...@@ -243,7 +242,7 @@ public class AnnotationConfigReactiveWebApplicationContext
+ StringUtils.collectionToCommaDelimitedString(this.basePackages) + StringUtils.collectionToCommaDelimitedString(this.basePackages)
+ "]"); + "]");
} }
scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()])); scanner.scan(StringUtils.toStringArray(this.basePackages));
} }
private void registerConfigLocations(AnnotatedBeanDefinitionReader reader, private void registerConfigLocations(AnnotatedBeanDefinitionReader reader,
......
...@@ -33,6 +33,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver; ...@@ -33,6 +33,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
...@@ -209,8 +210,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext ...@@ -209,8 +210,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
this.scanner.scan(this.basePackages); this.scanner.scan(this.basePackages);
} }
if (!this.annotatedClasses.isEmpty()) { if (!this.annotatedClasses.isEmpty()) {
this.reader.register(this.annotatedClasses this.reader.register(ClassUtils.toClassArray(this.annotatedClasses));
.toArray(new Class<?>[this.annotatedClasses.size()]));
} }
} }
......
...@@ -33,6 +33,7 @@ import org.apache.commons.logging.Log; ...@@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* Abstract base {@link ServletContextInitializer} to register {@link Filter}s in a * Abstract base {@link ServletContextInitializer} to register {@link Filter}s in a
...@@ -249,13 +250,13 @@ abstract class AbstractFilterRegistrationBean<T extends Filter> ...@@ -249,13 +250,13 @@ abstract class AbstractFilterRegistrationBean<T extends Filter>
this.logger.info("Mapping filter: '" + registration.getName() this.logger.info("Mapping filter: '" + registration.getName()
+ "' to servlets: " + servletNames); + "' to servlets: " + servletNames);
registration.addMappingForServletNames(dispatcherTypes, this.matchAfter, registration.addMappingForServletNames(dispatcherTypes, this.matchAfter,
servletNames.toArray(new String[servletNames.size()])); StringUtils.toStringArray(servletNames));
} }
if (!this.urlPatterns.isEmpty()) { if (!this.urlPatterns.isEmpty()) {
this.logger.info("Mapping filter: '" + registration.getName() this.logger.info("Mapping filter: '" + registration.getName()
+ "' to urls: " + this.urlPatterns); + "' to urls: " + this.urlPatterns);
registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter, registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter,
this.urlPatterns.toArray(new String[this.urlPatterns.size()])); StringUtils.toStringArray(this.urlPatterns));
} }
} }
} }
......
...@@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; ...@@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+ * A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+
...@@ -193,8 +194,7 @@ public class ServletRegistrationBean<T extends Servlet> ...@@ -193,8 +194,7 @@ public class ServletRegistrationBean<T extends Servlet>
@Override @Override
protected void configure(ServletRegistration.Dynamic registration) { protected void configure(ServletRegistration.Dynamic registration) {
super.configure(registration); super.configure(registration);
String[] urlMapping = this.urlMappings String[] urlMapping = StringUtils.toStringArray(this.urlMappings);
.toArray(new String[this.urlMappings.size()]);
if (urlMapping.length == 0 && this.alwaysMapUrl) { if (urlMapping.length == 0 && this.alwaysMapUrl) {
urlMapping = DEFAULT_MAPPINGS; urlMapping = DEFAULT_MAPPINGS;
} }
......
...@@ -32,6 +32,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver; ...@@ -32,6 +32,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
/** /**
...@@ -206,8 +207,7 @@ public class AnnotationConfigServletWebServerApplicationContext ...@@ -206,8 +207,7 @@ public class AnnotationConfigServletWebServerApplicationContext
this.scanner.scan(this.basePackages); this.scanner.scan(this.basePackages);
} }
if (!this.annotatedClasses.isEmpty()) { if (!this.annotatedClasses.isEmpty()) {
this.reader.register(this.annotatedClasses this.reader.register(ClassUtils.toClassArray(this.annotatedClasses));
.toArray(new Class<?>[this.annotatedClasses.size()]));
} }
} }
......
...@@ -255,8 +255,7 @@ public abstract class AbstractServletWebServerFactory ...@@ -255,8 +255,7 @@ public abstract class AbstractServletWebServerFactory
mergedInitializers.add(new SessionConfiguringInitializer(this.session)); mergedInitializers.add(new SessionConfiguringInitializer(this.session));
mergedInitializers.addAll(Arrays.asList(initializers)); mergedInitializers.addAll(Arrays.asList(initializers));
mergedInitializers.addAll(this.initializers); mergedInitializers.addAll(this.initializers);
return mergedInitializers return mergedInitializers.toArray(new ServletContextInitializer[0]);
.toArray(new ServletContextInitializer[mergedInitializers.size()]);
} }
/** /**
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -83,7 +83,7 @@ public class SimpleMainTests { ...@@ -83,7 +83,7 @@ public class SimpleMainTests {
list.add("--spring.main.sources=" list.add("--spring.main.sources="
+ StringUtils.arrayToCommaDelimitedString(args)); + StringUtils.arrayToCommaDelimitedString(args));
} }
return list.toArray(new String[list.size()]); return StringUtils.toStringArray(list);
} }
private String getOutput() { private String getOutput() {
......
...@@ -213,7 +213,7 @@ public class ConfigurationPropertiesTests { ...@@ -213,7 +213,7 @@ public class ConfigurationPropertiesTests {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
pairs.add("list[" + i + "]:" + i); pairs.add("list[" + i + "]:" + i);
} }
load(BasicConfiguration.class, pairs.toArray(new String[] {})); load(BasicConfiguration.class, StringUtils.toStringArray(pairs));
BasicProperties bean = this.context.getBean(BasicProperties.class); BasicProperties bean = this.context.getBean(BasicProperties.class);
assertThat(bean.list).hasSize(1000); assertThat(bean.list).hasSize(1000);
} }
......
...@@ -27,6 +27,7 @@ import org.springframework.core.io.ByteArrayResource; ...@@ -27,6 +27,7 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -64,7 +65,7 @@ public class YamlPropertySourceLoaderTests { ...@@ -64,7 +65,7 @@ public class YamlPropertySourceLoaderTests {
.load("resource", resource, null, (profile) -> true); .load("resource", resource, null, (profile) -> true);
assertThat(source).isNotNull(); assertThat(source).isNotNull();
assertThat(source.getPropertyNames()) assertThat(source.getPropertyNames())
.isEqualTo(expected.toArray(new String[] {})); .isEqualTo(StringUtils.toStringArray(expected));
} }
@Test @Test
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -65,7 +65,7 @@ public class JooqExamples implements CommandLineRunner { ...@@ -65,7 +65,7 @@ public class JooqExamples implements CommandLineRunner {
Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME) Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.from(BOOK).join(AUTHOR).on(BOOK.AUTHOR_ID.equal(AUTHOR.ID)) .from(BOOK).join(AUTHOR).on(BOOK.AUTHOR_ID.equal(AUTHOR.ID))
.where(BOOK.PUBLISHED_IN.equal(2015)); .where(BOOK.PUBLISHED_IN.equal(2015));
Object[] bind = query.getBindValues().toArray(new Object[] {}); Object[] bind = query.getBindValues().toArray(new Object[0]);
List<String> list = this.jdbc.query(query.getSQL(), bind, List<String> list = this.jdbc.query(query.getSQL(), bind,
new RowMapper<String>() { new RowMapper<String>() {
@Override @Override
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -26,6 +26,8 @@ import org.junit.rules.TestRule; ...@@ -26,6 +26,8 @@ import org.junit.rules.TestRule;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.springframework.util.StringUtils;
/** /**
* JUnit {@link TestRule} that launched a JVM and redirects its output to a test * JUnit {@link TestRule} that launched a JVM and redirects its output to a test
* method-specific location. * method-specific location.
...@@ -50,7 +52,7 @@ class JvmLauncher implements TestRule { ...@@ -50,7 +52,7 @@ class JvmLauncher implements TestRule {
command.addAll(Arrays.asList(args)); command.addAll(Arrays.asList(args));
File standardOut = new File(this.outputDirectory, name + ".out"); File standardOut = new File(this.outputDirectory, name + ".out");
File standardError = new File(this.outputDirectory, name + ".err"); File standardError = new File(this.outputDirectory, name + ".err");
Process process = new ProcessBuilder(command.toArray(new String[command.size()])) Process process = new ProcessBuilder(StringUtils.toStringArray(command))
.redirectError(standardError).redirectOutput(standardOut).start(); .redirectError(standardError).redirectOutput(standardOut).start();
return new LaunchedJvm(process, standardOut, standardError); return new LaunchedJvm(process, standardOut, standardError);
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -25,6 +25,7 @@ import java.util.List; ...@@ -25,6 +25,7 @@ import java.util.List;
import org.junit.rules.ExternalResource; import org.junit.rules.ExternalResource;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
/** /**
* Base {@link ExternalResource} for launching a Spring Boot application as part of a * Base {@link ExternalResource} for launching a Spring Boot application as part of a
...@@ -74,7 +75,7 @@ abstract class AbstractApplicationLauncher extends ExternalResource { ...@@ -74,7 +75,7 @@ abstract class AbstractApplicationLauncher extends ExternalResource {
arguments.add(System.getProperty("java.home") + "/bin/java"); arguments.add(System.getProperty("java.home") + "/bin/java");
arguments.addAll(getArguments(archive)); arguments.addAll(getArguments(archive));
ProcessBuilder processBuilder = new ProcessBuilder( ProcessBuilder processBuilder = new ProcessBuilder(
arguments.toArray(new String[arguments.size()])); StringUtils.toStringArray(arguments));
processBuilder.redirectOutput(Redirect.INHERIT); processBuilder.redirectOutput(Redirect.INHERIT);
processBuilder.redirectError(Redirect.INHERIT); processBuilder.redirectError(Redirect.INHERIT);
if (workingDirectory != null) { if (workingDirectory != null) {
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -53,7 +53,7 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests { ...@@ -53,7 +53,7 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests {
parameters.addAll(createParameters(packaging, "jetty", applicationLaunchers)); parameters.addAll(createParameters(packaging, "jetty", applicationLaunchers));
parameters.addAll(createParameters(packaging, "tomcat", applicationLaunchers)); parameters.addAll(createParameters(packaging, "tomcat", applicationLaunchers));
parameters.addAll(createParameters(packaging, "undertow", applicationLaunchers)); parameters.addAll(createParameters(packaging, "undertow", applicationLaunchers));
return parameters.toArray(new Object[parameters.size()]); return parameters.toArray(new Object[0]);
} }
private static List<Object> createParameters(String packaging, String container, private static List<Object> createParameters(String packaging, String container,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment