Polish Collection.toArray

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

Fixes gh-12160
pull/12202/head
Phillip Webb 7 years ago
parent 358adcd6e3
commit 4b9c3c137e

@ -32,6 +32,7 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.util.StringUtils;
/**
* Selects configuration classes for the management context configuration. Entries are
@ -65,7 +66,7 @@ class ManagementContextConfigurationImportSelector
names.add(configuration.getClassName());
}
}
return names.toArray(new String[names.size()]);
return StringUtils.toStringArray(names);
}
private List<ManagementConfiguration> getConfigurations() {

@ -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.server.ServletWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ClassUtils;
/**
* A {@link ManagementContextFactory} for servlet-based web applications.
@ -47,7 +48,7 @@ class ServletManagementContextFactory implements ManagementContextFactory {
child.setParent(parent);
List<Class<?>> combinedClasses = new ArrayList<>(Arrays.asList(configClasses));
combinedClasses.add(ServletWebServerFactoryAutoConfiguration.class);
child.register(combinedClasses.toArray(new Class<?>[combinedClasses.size()]));
child.register(ClassUtils.toClassArray(combinedClasses));
registerServletWebServerFactory(parent, child);
return child;
}

@ -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.trace.http.HttpTraceEndpointAutoConfiguration;
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.
@ -51,7 +52,7 @@ final class EndpointAutoConfigurationClasses {
all.add(ThreadDumpEndpointAutoConfiguration.class);
all.add(HttpTraceEndpointAutoConfiguration.class);
all.add(MappingsEndpointAutoConfiguration.class);
ALL = all.toArray(new Class<?>[] {});
ALL = ClassUtils.toClassArray(all);
}
private EndpointAutoConfigurationClasses() {

@ -27,6 +27,7 @@ import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* {@link HealthIndicator} for an Elasticsearch cluster.
@ -53,8 +54,8 @@ public class ElasticsearchHealthIndicator extends AbstractHealthIndicator {
*/
public ElasticsearchHealthIndicator(Client client, long responseTimeout,
List<String> indices) {
this(client, responseTimeout, (indices == null ? null
: indices.toArray(new String[indices.size()])));
this(client, responseTimeout,
(indices == null ? null : StringUtils.toStringArray(indices)));
}
/**

@ -94,23 +94,18 @@ public class JerseyEndpointResourceFactory {
Builder resourceBuilder = Resource.builder()
.path(endpointMapping.createSubPath(requestPredicate.getPath()));
resourceBuilder.addMethod(requestPredicate.getHttpMethod().name())
.consumes(toStringArray(requestPredicate.getConsumes()))
.produces(toStringArray(requestPredicate.getProduces()))
.consumes(StringUtils.toStringArray(requestPredicate.getConsumes()))
.produces(StringUtils.toStringArray(requestPredicate.getProduces()))
.handledBy(new OperationInflector(operation,
!requestPredicate.getConsumes().isEmpty()));
return resourceBuilder.build();
}
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private Resource createEndpointLinksResource(String endpointPath,
EndpointMediaTypes endpointMediaTypes, EndpointLinksResolver linksResolver) {
Builder resourceBuilder = Resource.builder().path(endpointPath);
resourceBuilder.addMethod("GET")
.produces(endpointMediaTypes.getProduced()
.toArray(new String[endpointMediaTypes.getProduced().size()]))
.produces(StringUtils.toStringArray(endpointMediaTypes.getProduced()))
.handledBy(new EndpointLinksInflector(linksResolver));
return resourceBuilder.build();
}

@ -167,25 +167,20 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.valueOf(predicate.getHttpMethod().name()));
ConsumesRequestCondition consumes = new ConsumesRequestCondition(
toStringArray(predicate.getConsumes()));
StringUtils.toStringArray(predicate.getConsumes()));
ProducesRequestCondition produces = new ProducesRequestCondition(
toStringArray(predicate.getProduces()));
StringUtils.toStringArray(predicate.getProduces()));
return new RequestMappingInfo(null, patterns, methods, null, null, consumes,
produces, null);
}
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private void registerLinksMapping() {
PatternsRequestCondition patterns = new PatternsRequestCondition(
pathPatternParser.parse(this.endpointMapping.getPath()));
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.GET);
ProducesRequestCondition produces = new ProducesRequestCondition(
this.endpointMediaTypes.getProduced().toArray(
new String[this.endpointMediaTypes.getProduced().size()]));
StringUtils.toStringArray(this.endpointMediaTypes.getProduced()));
RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null,
null, produces, null);
registerMapping(mapping, this, this.linksMethod);

@ -155,24 +155,20 @@ public abstract class AbstractWebMvcEndpointHandlerMapping
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.valueOf(predicate.getHttpMethod().name()));
ConsumesRequestCondition consumes = new ConsumesRequestCondition(
toStringArray(predicate.getConsumes()));
StringUtils.toStringArray(predicate.getConsumes()));
ProducesRequestCondition produces = new ProducesRequestCondition(
toStringArray(predicate.getProduces()));
StringUtils.toStringArray(predicate.getProduces()));
return new RequestMappingInfo(null, patterns, methods, null, null, consumes,
produces, null);
}
private String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
private void registerLinksMapping() {
PatternsRequestCondition patterns = patternsRequestConditionForPattern("");
RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition(
RequestMethod.GET);
ProducesRequestCondition produces = new ProducesRequestCondition(
this.endpointMediaTypes.getProduced().toArray(
new String[this.endpointMediaTypes.getProduced().size()]));
this.endpointMediaTypes.getProduced().toArray(StringUtils
.toStringArray(this.endpointMediaTypes.getProduced())));
RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null,
null, produces, null);
registerMapping(mapping, this, this.linksMethod);

@ -35,6 +35,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -177,8 +178,7 @@ public class ConfigurationPropertiesReportEndpointTests {
ConfigurationPropertiesReportEndpoint endpoint = context
.getBean(ConfigurationPropertiesReportEndpoint.class);
if (!CollectionUtils.isEmpty(keysToSanitize)) {
endpoint.setKeysToSanitize(
keysToSanitize.toArray(new String[keysToSanitize.size()]));
endpoint.setKeysToSanitize(StringUtils.toStringArray(keysToSanitize));
}
properties.accept(context, endpoint.configurationProperties().getContexts()
.get(context.getId()));

@ -264,7 +264,7 @@ public class EndpointDiscovererTests {
methods.add(findTestEndpointMethod("getOne", String.class));
methods.add(findTestEndpointMethod("update", String.class, 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) {

@ -47,6 +47,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
/**
* {@link BlockJUnit4ClassRunner} for Jersey.
@ -63,7 +64,7 @@ class JerseyEndpointsRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
classes.add(JerseyEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()]));
context.register(ClassUtils.toClassArray(classes));
context.refresh();
return context;
}

@ -44,6 +44,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.ClassUtils;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
@ -62,7 +63,7 @@ class WebFluxEndpointsRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext();
classes.add(WebFluxEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()]));
context.register(ClassUtils.toClassArray(classes));
context.refresh();
return context;
}

@ -43,6 +43,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.util.ClassUtils;
import org.springframework.web.cors.CorsConfiguration;
/**
@ -60,7 +61,7 @@ class WebMvcEndpointRunner extends AbstractWebEndpointRunner {
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
classes.add(WebMvcEndpointConfiguration.class);
context.register(classes.toArray(new Class<?>[classes.size()]));
context.register(ClassUtils.toClassArray(classes));
context.refresh();
return context;
}

@ -50,6 +50,7 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration
@ -100,7 +101,7 @@ public class AutoConfigurationImportSelector
configurations.removeAll(exclusions);
configurations = filter(configurations, autoConfigurationMetadata);
fireAutoConfigurationImportEvents(configurations, exclusions);
return configurations.toArray(new String[configurations.size()]);
return StringUtils.toStringArray(configurations);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
@ -235,7 +236,7 @@ public class AutoConfigurationImportSelector
private List<String> filter(List<String> configurations,
AutoConfigurationMetadata autoConfigurationMetadata) {
long startTime = System.nanoTime();
String[] candidates = configurations.toArray(new String[configurations.size()]);
String[] candidates = StringUtils.toStringArray(configurations);
boolean[] skip = new boolean[candidates.length];
boolean skipped = false;
for (AutoConfigurationImportFilter filter : getAutoConfigurationImportFilters()) {

@ -114,7 +114,7 @@ public abstract class AutoConfigurationPackages {
Set<String> merged = new LinkedHashSet<>();
merged.addAll(Arrays.asList(existing));
merged.addAll(Arrays.asList(packageNames));
return merged.toArray(new String[merged.size()]);
return StringUtils.toStringArray(merged);
}
/**

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -32,6 +32,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/**
* Couchbase cache configuration.
@ -66,7 +67,7 @@ public class CouchbaseCacheConfiguration {
Couchbase couchbase = this.cacheProperties.getCouchbase();
PropertyMapper.get().from(couchbase::getExpiration).whenNonNull()
.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);
return this.customizers.customize(cacheManager);
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Cassandra.
@ -80,7 +81,7 @@ public class CassandraAutoConfiguration {
map.from(properties::isSsl).whenTrue().toCall(builder::withSSL);
map.from(this::getPoolingOptions).to(builder::withPoolingOptions);
map.from(properties::getContactPoints)
.as((list) -> list.toArray(new String[list.size()]))
.as((list) -> StringUtils.toStringArray(list))
.to(builder::addContactPoints);
customize(builder);
return builder.build();

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -40,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.web.support.OpenSessionInViewInterceptor;
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.WebMvcConfigurer;
@ -106,7 +107,7 @@ public class Neo4jDataAutoConfiguration {
if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) {
packages = AutoConfigurationPackages.get(applicationContext);
}
return packages.toArray(new String[packages.size()]);
return StringUtils.toStringArray(packages);
}
@Configuration

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -120,7 +120,7 @@ public class EntityScanPackages {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(EntityScanPackages.class);
beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0,
packageNames.toArray(new String[packageNames.size()]));
StringUtils.toStringArray(packageNames));
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(BEAN, beanDefinition);
}
@ -134,7 +134,7 @@ public class EntityScanPackages {
Set<String> merged = new LinkedHashSet<>();
merged.addAll(Arrays.asList(existing));
merged.addAll(packageNames);
return merged.toArray(new String[merged.size()]);
return StringUtils.toStringArray(merged);
}
/**

@ -57,6 +57,7 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Flyway database migrations.
@ -137,7 +138,7 @@ public class FlywayAutoConfiguration {
String password = getProperty(this.properties::getPassword,
this.dataSourceProperties::getPassword);
flyway.setDataSource(url, user, password,
this.properties.getInitSqls().toArray(new String[0]));
StringUtils.toStringArray(this.properties.getInitSqls()));
}
else if (this.flywayDataSource != null) {
flyway.setDataSource(this.flywayDataSource);
@ -145,8 +146,7 @@ public class FlywayAutoConfiguration {
else {
flyway.setDataSource(this.dataSource);
}
flyway.setCallbacks(this.flywayCallbacks
.toArray(new FlywayCallback[this.flywayCallbacks.size()]));
flyway.setCallbacks(this.flywayCallbacks.toArray(new FlywayCallback[0]));
String[] locations = new LocationResolver(flyway.getDataSource())
.resolveLocations(this.properties.getLocations());
checkLocationExists(locations);
@ -241,7 +241,7 @@ public class FlywayAutoConfiguration {
}
public String[] resolveLocations(Collection<String> locations) {
return resolveLocations(locations.toArray(new String[locations.size()]));
return resolveLocations(StringUtils.toStringArray(locations));
}
public String[] resolveLocations(String[] locations) {

@ -337,8 +337,7 @@ public class JacksonAutoConfiguration {
private void configureModules(Jackson2ObjectMapperBuilder builder) {
Collection<Module> moduleBeans = getBeans(this.applicationContext,
Module.class);
builder.modulesToInstall(
moduleBeans.toArray(new Module[moduleBeans.size()]));
builder.modulesToInstall(moduleBeans.toArray(new Module[0]));
}
private void configureLocale(Jackson2ObjectMapperBuilder builder) {

@ -113,7 +113,7 @@ public class EmbeddedLdapAutoConfiguration {
@Bean
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);
if (hasCredentials(this.embeddedProperties.getCredential())) {
config.addAdditionalBindCredentials(

@ -55,6 +55,7 @@ import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.jta.JtaTransactionManager;
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.WebMvcConfigurer;
@ -160,13 +161,13 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) {
packages = AutoConfigurationPackages.get(this.beanFactory);
}
return packages.toArray(new String[packages.size()]);
return StringUtils.toStringArray(packages);
}
private String[] getMappingResources() {
List<String> mappingResources = this.properties.getMappingResources();
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
import org.springframework.security.oauth2.client.registration.ClientRegistration.Builder;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
import org.springframework.util.StringUtils;
/**
* Adapter class to convert {@link OAuth2ClientProperties} to a
@ -63,8 +64,7 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new)
.to(builder::authorizationGrantType);
map.from(properties::getRedirectUriTemplate).to(builder::redirectUriTemplate);
map.from(properties::getScope)
.as((scope) -> scope.toArray(new String[scope.size()]))
map.from(properties::getScope).as((scope) -> StringUtils.toStringArray(scope))
.to(builder::scope);
map.from(properties::getClientName).to(builder::clientName);
return builder.build();

@ -35,6 +35,7 @@ import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.StringUtils;
/**
* Default user {@link Configuration} for a reactive web application. Configures a
@ -72,7 +73,7 @@ public class ReactiveUserDetailsServiceAutoConfiguration {
private UserDetails getUserDetails(SecurityProperties.User user, String password) {
List<String> roles = user.getRoles();
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,

@ -36,6 +36,7 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.util.StringUtils;
/**
* Configuration for a Spring Security in-memory {@link AuthenticationManager}. Adds an
@ -71,7 +72,7 @@ public class UserDetailsServiceAutoConfiguration {
List<String> roles = user.getRoles();
return new InMemoryUserDetailsManager(User.withUsername(user.getName())
.password(getOrDeducePassword(user, passwordEncoder.getIfAvailable()))
.roles(roles.toArray(new String[roles.size()])).build());
.roles(StringUtils.toStringArray(roles)).build());
}
public String getOrDeducePassword(SecurityProperties.User user,

@ -48,6 +48,7 @@ import org.springframework.core.type.AnnotationMetadata;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Session.
@ -113,7 +114,7 @@ public class SessionAutoConfiguration {
imports.add(SessionStoreMappings.getConfigurationClass(webApplicationType,
types[i]));
}
return imports.toArray(new String[imports.size()]);
return StringUtils.toStringArray(imports);
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -92,7 +93,7 @@ public class CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests {
CouchbaseReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return StringUtils.toStringArray(names);
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -41,6 +41,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -164,7 +165,7 @@ public class MixedMongoRepositoriesAutoConfigurationTests {
MongoRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return StringUtils.toStringArray(names);
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -36,6 +36,7 @@ import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -93,7 +94,7 @@ public class MongoReactiveAndBlockingRepositoriesAutoConfigurationTests {
MongoReactiveRepositoriesAutoConfiguration.class }) {
names.add(type.getName());
}
return names.toArray(new String[0]);
return StringUtils.toStringArray(names);
}
}

@ -47,6 +47,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ -226,7 +227,7 @@ public class DataSourceAutoConfigurationTests {
private <T extends DataSource> void assertDataSource(Class<T> expectedType,
List<String> hiddenPackages, Consumer<T> consumer) {
FilteredClassLoader classLoader = new FilteredClassLoader(
hiddenPackages.toArray(new String[hiddenPackages.size()]));
StringUtils.toStringArray(hiddenPackages));
this.contextRunner.withClassLoader(classLoader).run((context) -> {
DataSource bean = context.getBean(DataSource.class);
assertThat(bean).isInstanceOf(expectedType);

@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ -89,8 +90,9 @@ public class ActiveMQAutoConfigurationTests {
.isEqualTo(defaultFactory.getSendTimeout());
assertThat(connectionFactory.isTrustAllPackages())
.isEqualTo(defaultFactory.isTrustAllPackages());
assertThat(connectionFactory.getTrustedPackages()).containsExactly(
defaultFactory.getTrustedPackages().toArray(new String[] {}));
assertThat(connectionFactory.getTrustedPackages())
.containsExactly(StringUtils
.toStringArray(defaultFactory.getTrustedPackages()));
});
}
@ -113,8 +115,7 @@ public class ActiveMQAutoConfigurationTests {
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
assertThat(connectionFactory.isNonBlockingRedelivery())
.isTrue();
assertThat(connectionFactory.isNonBlockingRedelivery()).isTrue();
assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000);
assertThat(connectionFactory.isTrustAllPackages()).isFalse();
assertThat(connectionFactory.getTrustedPackages())
@ -177,23 +178,19 @@ public class ActiveMQAutoConfigurationTests {
.hasSize(1);
PooledConnectionFactory connectionFactory = context
.getBean(PooledConnectionFactory.class);
assertThat(connectionFactory.isBlockIfSessionPoolIsFull())
.isFalse();
assertThat(connectionFactory.isBlockIfSessionPoolIsFull()).isFalse();
assertThat(connectionFactory.getBlockIfSessionPoolIsFullTimeout())
.isEqualTo(64);
assertThat(connectionFactory.isCreateConnectionOnStartup())
.isFalse();
assertThat(connectionFactory.isCreateConnectionOnStartup()).isFalse();
assertThat(connectionFactory.getExpiryTimeout()).isEqualTo(4096);
assertThat(connectionFactory.getIdleTimeout()).isEqualTo(512);
assertThat(connectionFactory.getMaxConnections()).isEqualTo(256);
assertThat(connectionFactory.getMaximumActiveSessionPerConnection())
.isEqualTo(1024);
assertThat(connectionFactory.isReconnectOnException())
.isFalse();
assertThat(connectionFactory.isReconnectOnException()).isFalse();
assertThat(connectionFactory.getTimeBetweenExpirationCheckMillis())
.isEqualTo(2048);
assertThat(connectionFactory.isUseAnonymousProducers())
.isFalse();
assertThat(connectionFactory.isUseAnonymousProducers()).isFalse();
});
}

@ -51,6 +51,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.PostMapping;
@ -228,7 +229,7 @@ public class BasicErrorControllerIntegrationTests {
args.addAll(Arrays.asList(arguments));
}
this.context = SpringApplication.run(TestConfiguration.class,
args.toArray(new String[args.size()]));
StringUtils.toStringArray(args));
}
@Target(ElementType.TYPE)

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ public final class SpringCli {
}
}
}
return urls.toArray(new URL[urls.size()]);
return urls.toArray(new URL[0]);
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -195,7 +195,7 @@ public class CommandRunner implements Iterable<Command> {
}
rtn.add(arg);
}
return rtn.toArray(new String[rtn.size()]);
return StringUtils.toStringArray(rtn);
}
/**

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import joptsimple.OptionSet;
import org.springframework.boot.cli.util.ResourceUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Extract source file options (anything following '--' in an {@link OptionSet}).
@ -125,7 +126,11 @@ public class SourceOptions {
}
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() {
@ -133,7 +138,7 @@ public class SourceOptions {
}
public String[] getSourcesArray() {
return this.sources.toArray(new String[this.sources.size()]);
return StringUtils.toStringArray(this.sources);
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import org.springframework.boot.cli.command.AbstractCommand;
import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.status.ExitStatus;
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
@ -49,7 +50,7 @@ class RunProcessCommand extends AbstractCommand {
protected ExitStatus run(Collection<String> args) throws IOException {
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) {
return ExitStatus.OK;
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -169,7 +169,7 @@ public class DependencyManagementBomTransformation
private void updateDependencyResolutionContext(
List<Map<String, String>> bomDependencies) {
URI[] uris = Grape.getInstance().resolve(null,
bomDependencies.toArray(new Map[bomDependencies.size()]));
bomDependencies.toArray(new Map[0]));
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
for (URI uri : uris) {
try {

@ -186,7 +186,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
findGroovyJarsFromClassPath(urls);
}
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) {

@ -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.util.ResourceUtils;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.ClassUtils;
/**
* Compiler for Groovy sources. Primarily a simple Facade for
@ -220,7 +221,7 @@ public class GroovyCompiler {
classes.add(0, mainClass);
}
return classes.toArray(new Class<?>[classes.size()]);
return ClassUtils.toClassArray(classes);
}
@SuppressWarnings("rawtypes")

@ -290,7 +290,7 @@ public class AetherGrapeEngine implements GrapeEngine {
for (File file : files) {
uris.add(file.toURI());
}
return uris.toArray(new URI[uris.size()]);
return uris.toArray(new URI[0]);
}
catch (Exception ex) {
throw new DependencyResolutionFailedException(ex);

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -43,6 +43,7 @@ import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
/**
* {@link TestRule} that can be used to invoke CLI commands.
@ -84,7 +85,7 @@ public class CliTester implements TestRule {
"--classpath=.:" + new File("target/test-classes").getAbsolutePath());
}
Future<RunCommand> future = submitCommand(new RunCommand(),
updatedArgs.toArray(new String[updatedArgs.size()]));
StringUtils.toStringArray(updatedArgs));
this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));
return getOutput();
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -122,7 +122,7 @@ public class DevToolsProperties {
allExclude.addAll(
StringUtils.commaDelimitedListToSet(this.additionalExclude));
}
return allExclude.toArray(new String[allExclude.size()]);
return StringUtils.toStringArray(allExclude);
}
public String getExclude() {

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -79,7 +79,7 @@ final class ChangeableUrls implements Iterable<URL> {
}
public URL[] toArray() {
return this.urls.toArray(new URL[this.urls.size()]);
return this.urls.toArray(new URL[0]);
}
public List<URL> toList() {

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -119,7 +119,7 @@ final class ClassLoaderFilesResourcePatternResolver implements ResourcePatternRe
}
}
resources.addAll(getAdditionalResources(locationPattern));
return resources.toArray(new Resource[resources.size()]);
return resources.toArray(new Resource[0]);
}
private List<Resource> getAdditionalResources(String locationPattern)

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -273,7 +273,7 @@ public class Restarter {
private Throwable doStart() throws Exception {
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);
ClassLoader classLoader = new RestartClassLoader(this.applicationClassLoader,
urls, updatedFiles, this.logger);

@ -41,6 +41,7 @@ import org.springframework.test.web.servlet.result.PrintingResultHandler;
import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
/**
@ -133,7 +134,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
builder.addFilters(filter);
}
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 {
if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) {
properties.add("server.port=-1");
}
return properties.toArray(new String[properties.size()]);
return StringUtils.toStringArray(properties);
}
private void disableJmx(List<String> properties) {
@ -187,9 +187,8 @@ public class SpringBootContextLoader extends AbstractContextLoader {
private ConfigurationPropertySource convertToConfigurationPropertySource(
List<String> properties) {
String[] array = properties.toArray(new String[properties.size()]);
return new MapConfigurationPropertySource(
TestPropertySourceUtils.convertInlinedPropertiesToMap(array));
return new MapConfigurationPropertySource(TestPropertySourceUtils
.convertInlinedPropertiesToMap(StringUtils.toStringArray(properties)));
}
/**

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -52,6 +52,7 @@ import org.springframework.test.context.web.WebMergedContextConfiguration;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* {@link TestContextBootstrapper} for Spring Boot. Provides support for
@ -137,7 +138,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
if (configAttributes.getClasses() != null) {
combined.addAll(Arrays.asList(configAttributes.getClasses()));
}
configAttributes.setClasses(combined.toArray(new Class<?>[combined.size()]));
configAttributes.setClasses(ClassUtils.toClassArray(combined));
}
@Override
@ -153,8 +154,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
List<String> propertySourceProperties = getAndProcessPropertySourceProperties(
mergedConfig);
mergedConfig = createModifiedConfig(mergedConfig, classes,
propertySourceProperties
.toArray(new String[propertySourceProperties.size()]));
StringUtils.toStringArray(propertySourceProperties));
WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass());
if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) {
WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -28,6 +28,7 @@ import org.mockito.Mockito;
import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@ -147,7 +148,7 @@ class MockDefinition extends Definition {
settings.name(name);
}
if (!this.extraInterfaces.isEmpty()) {
settings.extraInterfaces(this.extraInterfaces.toArray(new Class<?>[] {}));
settings.extraInterfaces(ClassUtils.toClassArray(this.extraInterfaces));
}
settings.defaultAnswer(this.answer);
if (this.serializable) {

@ -279,7 +279,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
}
}
beans.removeIf(this::isScopedTarget);
return beans.toArray(new String[beans.size()]);
return StringUtils.toStringArray(beans);
}
private boolean isScopedTarget(String beanName) {

@ -123,7 +123,7 @@ public class TestJarFile {
public File getFile(String extension) throws IOException {
File file = this.temporaryFolder.newFile();
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;
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public abstract class Launcher {
for (Archive archive : archives) {
urls.add(archive.getUrl());
}
return createClassLoader(urls.toArray(new URL[urls.size()]));
return createClassLoader(urls.toArray(new URL[0]));
}
/**

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -369,7 +369,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
addResources(urls);
addProjectClasses(urls);
addDependencies(urls);
return urls.toArray(new URL[urls.size()]);
return urls.toArray(new URL[0]);
}
catch (IOException ex) {
throw new MojoExecutionException("Unable to build classpath", ex);

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -262,7 +262,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
if (!this.includeSystemScope) {
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 {

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ class RunArguments {
}
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) {

@ -71,7 +71,7 @@ public class RunMojo extends AbstractRunMojo {
new JavaExecutable().toString());
Runtime.getRuntime()
.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) {
return;
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -105,7 +105,7 @@ public class StartMojo extends AbstractRunMojo {
try {
RunProcess runProcess = new RunProcess(workingDirectory,
new JavaExecutable().toString());
runProcess.run(false, args.toArray(new String[args.size()]));
runProcess.run(false, args.toArray(new String[0]));
return runProcess;
}
catch (Exception ex) {

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -105,7 +105,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
extractedUrls.add(url);
}
});
return extractedUrls.toArray(new URL[extractedUrls.size()]);
return extractedUrls.toArray(new URL[0]);
}
private Stream<URL> doExtractUrls(ClassLoader classLoader) throws Exception {
@ -158,7 +158,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
processedUrls.add(url);
}
}
return processedUrls.toArray(new URL[processedUrls.size()]);
return processedUrls.toArray(new URL[0]);
}
private List<URL> getAdditionalUrls(Class<?> testClass) throws Exception {

@ -380,7 +380,7 @@ public class SpringApplication {
// Load the sources
Set<Object> sources = getAllSources();
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);
}
@ -516,7 +516,7 @@ public class SpringApplication {
// But these ones should go first (last wins in a property key clash)
Set<String> profiles = new LinkedHashSet<>(this.additionalProfiles);
profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
environment.setActiveProfiles(StringUtils.toStringArray(profiles));
}
private void configureIgnoreBeanInfo(ConfigurableEnvironment environment) {

@ -37,6 +37,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
/**
* Builder for {@link SpringApplication} and {@link ApplicationContext} instances with
@ -455,16 +456,16 @@ public class SpringApplicationBuilder {
*/
public SpringApplicationBuilder profiles(String... profiles) {
this.additionalProfiles.addAll(Arrays.asList(profiles));
this.application.setAdditionalProfiles(this.additionalProfiles
.toArray(new String[this.additionalProfiles.size()]));
this.application.setAdditionalProfiles(
StringUtils.toStringArray(this.additionalProfiles));
return this;
}
private SpringApplicationBuilder additionalProfiles(
Collection<String> additionalProfiles) {
this.additionalProfiles = new LinkedHashSet<>(additionalProfiles);
this.application.setAdditionalProfiles(this.additionalProfiles
.toArray(new String[this.additionalProfiles.size()]));
this.application.setAdditionalProfiles(
StringUtils.toStringArray(this.additionalProfiles));
return this;
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
@ -34,6 +35,7 @@ import org.springframework.core.OrderComparator;
import org.springframework.core.Ordered;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* A set of {@link Configuration @Configuration} classes that can be registered in
@ -114,12 +116,17 @@ public abstract class Configurations {
* @return configuration classes in registration order
*/
public static Class<?>[] getClasses(Collection<Configurations> configurations) {
List<Configurations> orderedConfigurations = new ArrayList<>(configurations);
orderedConfigurations.sort(COMPARATOR);
List<Configurations> collated = collate(orderedConfigurations);
return collated.stream().flatMap((c) -> c.getClasses().stream())
.collect(Collectors.toCollection(LinkedHashSet::new))
.toArray(new Class<?>[0]);
List<Configurations> ordered = new ArrayList<>(configurations);
ordered.sort(COMPARATOR);
List<Configurations> collated = collate(ordered);
LinkedHashSet<Class<?>> classes = collated.stream()
.flatMap(Configurations::streamClasses)
.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(

@ -565,7 +565,7 @@ public class ConfigFileApplicationListener
// But this one should go first (last wins in a property key clash)
profiles.add(profile.getName());
profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
environment.setActiveProfiles(StringUtils.toStringArray(profiles));
}
private Set<String> getSearchLocations() {

@ -113,7 +113,7 @@ class ConfigurationPropertiesBinder {
}
if (!validators.isEmpty()) {
handler = new ValidationBindHandler(handler,
validators.toArray(new Validator[validators.size()]));
validators.toArray(new Validator[0]));
}
return handler;
}

@ -460,8 +460,7 @@ public final class ConfigurationPropertyName
elements.add(elementValue);
}
});
return new ConfigurationPropertyName(
elements.toArray(new CharSequence[elements.size()]));
return new ConfigurationPropertyName(elements.toArray(new CharSequence[0]));
}
/**
@ -508,8 +507,7 @@ public final class ConfigurationPropertyName
elements.add(elementValue);
}
});
return new ConfigurationPropertyName(
elements.toArray(new CharSequence[elements.size()]));
return new ConfigurationPropertyName(elements.toArray(new CharSequence[0]));
}
private static void process(CharSequence name, char separator,

@ -121,7 +121,7 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
mappings.add(mapping);
}
}
result = mappings.toArray(new PropertyMapping[mappings.size()]);
result = mappings.toArray(new PropertyMapping[0]);
if (cache != null) {
cache.setMappings(result);
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.util.StringUtils;
/**
* {@link BeanFactoryPostProcessor} to automatically setup the recommended
@ -65,7 +66,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor
addDependencies(beanFactory, "javax.jms.ConnectionFactory", dependsOn);
addDependencies(beanFactory, "javax.sql.DataSource", dependsOn);
if (dependsOn.size() != initialSize) {
bean.setDependsOn(dependsOn.toArray(new String[dependsOn.size()]));
bean.setDependsOn(StringUtils.toStringArray(dependsOn));
}
}
@ -77,7 +78,7 @@ public class AtomikosDependsOnBeanFactoryPostProcessor
BeanDefinition bean = beanFactory.getBeanDefinition(messageDrivenContainer);
Set<String> dependsOn = new LinkedHashSet<>(asList(bean.getDependsOn()));
dependsOn.addAll(asList(transactionManagers));
bean.setDependsOn(dependsOn.toArray(new String[dependsOn.size()]));
bean.setDependsOn(StringUtils.toStringArray(dependsOn));
}
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -119,8 +119,7 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
Collections.addAll(supportedConfigLocations, "log4j2.json", "log4j2.jsn");
}
supportedConfigLocations.add("log4j2.xml");
return supportedConfigLocations
.toArray(new String[supportedConfigLocations.size()]);
return StringUtils.toStringArray(supportedConfigLocations);
}
protected boolean isClassAvailable(String className) {

@ -30,6 +30,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* Convenient builder for JPA EntityManagerFactory instances. Collects common
@ -142,7 +143,7 @@ public class EntityManagerFactoryBuilder {
for (Class<?> type : basePackageClasses) {
packages.add(ClassUtils.getPackageName(type));
}
this.packagesToScan = packages.toArray(new String[0]);
this.packagesToScan = StringUtils.toStringArray(packages);
return this;
}

@ -277,8 +277,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
resources.add(resource);
}
}
handler.setBaseResource(new ResourceCollection(
resources.toArray(new Resource[resources.size()])));
handler.setBaseResource(
new ResourceCollection(resources.toArray(new Resource[0])));
}
catch (Exception ex) {
throw new IllegalStateException(ex);
@ -343,7 +343,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
configurations.addAll(getConfigurations());
configurations.add(getErrorPageConfiguration());
configurations.add(getMimeTypeConfiguration());
return configurations.toArray(new Configuration[configurations.size()]);
return configurations.toArray(new Configuration[0]);
}
/**

@ -74,7 +74,7 @@ final class UndertowCompressionConfigurer {
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 {

@ -387,7 +387,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
}
resourceManagers.add(new MetaInfResourcesResourceManager(resourceJarUrls));
return new CompositeResourceManager(
resourceManagers.toArray(new ResourceManager[resourceManagers.size()]));
resourceManagers.toArray(new ResourceManager[0]));
}
private File getCanonicalDocumentRoot(File docBase) {

@ -233,8 +233,7 @@ public class AnnotationConfigReactiveWebApplicationContext
+ StringUtils.collectionToCommaDelimitedString(this.annotatedClasses)
+ "]");
}
reader.register(this.annotatedClasses
.toArray(new Class<?>[this.annotatedClasses.size()]));
reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
private void scanBasePackages(ClassPathBeanDefinitionScanner scanner) {
@ -243,7 +242,7 @@ public class AnnotationConfigReactiveWebApplicationContext
+ 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,

@ -33,6 +33,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
@ -209,8 +210,7 @@ public class AnnotationConfigReactiveWebServerApplicationContext
this.scanner.scan(this.basePackages);
}
if (!this.annotatedClasses.isEmpty()) {
this.reader.register(this.annotatedClasses
.toArray(new Class<?>[this.annotatedClasses.size()]));
this.reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
}

@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Abstract base {@link ServletContextInitializer} to register {@link Filter}s in a
@ -249,13 +250,13 @@ abstract class AbstractFilterRegistrationBean<T extends Filter>
this.logger.info("Mapping filter: '" + registration.getName()
+ "' to servlets: " + servletNames);
registration.addMappingForServletNames(dispatcherTypes, this.matchAfter,
servletNames.toArray(new String[servletNames.size()]));
StringUtils.toStringArray(servletNames));
}
if (!this.urlPatterns.isEmpty()) {
this.logger.info("Mapping filter: '" + registration.getName()
+ "' to urls: " + this.urlPatterns);
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;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+
@ -193,8 +194,7 @@ public class ServletRegistrationBean<T extends Servlet>
@Override
protected void configure(ServletRegistration.Dynamic registration) {
super.configure(registration);
String[] urlMapping = this.urlMappings
.toArray(new String[this.urlMappings.size()]);
String[] urlMapping = StringUtils.toStringArray(this.urlMappings);
if (urlMapping.length == 0 && this.alwaysMapUrl) {
urlMapping = DEFAULT_MAPPINGS;
}

@ -32,6 +32,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
/**
@ -206,8 +207,7 @@ public class AnnotationConfigServletWebServerApplicationContext
this.scanner.scan(this.basePackages);
}
if (!this.annotatedClasses.isEmpty()) {
this.reader.register(this.annotatedClasses
.toArray(new Class<?>[this.annotatedClasses.size()]));
this.reader.register(ClassUtils.toClassArray(this.annotatedClasses));
}
}

@ -255,8 +255,7 @@ public abstract class AbstractServletWebServerFactory
mergedInitializers.add(new SessionConfiguringInitializer(this.session));
mergedInitializers.addAll(Arrays.asList(initializers));
mergedInitializers.addAll(this.initializers);
return mergedInitializers
.toArray(new ServletContextInitializer[mergedInitializers.size()]);
return mergedInitializers.toArray(new ServletContextInitializer[0]);
}
/**

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -83,7 +83,7 @@ public class SimpleMainTests {
list.add("--spring.main.sources="
+ StringUtils.arrayToCommaDelimitedString(args));
}
return list.toArray(new String[list.size()]);
return StringUtils.toStringArray(list);
}
private String getOutput() {

@ -213,7 +213,7 @@ public class ConfigurationPropertiesTests {
for (int i = 0; i < 1000; 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);
assertThat(bean.list).hasSize(1000);
}

@ -27,6 +27,7 @@ import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -64,7 +65,7 @@ public class YamlPropertySourceLoaderTests {
.load("resource", resource, null, (profile) -> true);
assertThat(source).isNotNull();
assertThat(source.getPropertyNames())
.isEqualTo(expected.toArray(new String[] {}));
.isEqualTo(StringUtils.toStringArray(expected));
}
@Test

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -65,7 +65,7 @@ public class JooqExamples implements CommandLineRunner {
Query query = this.dsl.select(BOOK.TITLE, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.from(BOOK).join(AUTHOR).on(BOOK.AUTHOR_ID.equal(AUTHOR.ID))
.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,
new RowMapper<String>() {
@Override

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -26,6 +26,8 @@ import org.junit.rules.TestRule;
import org.junit.runner.Description;
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
* method-specific location.
@ -50,7 +52,7 @@ class JvmLauncher implements TestRule {
command.addAll(Arrays.asList(args));
File standardOut = new File(this.outputDirectory, name + ".out");
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();
return new LaunchedJvm(process, standardOut, standardError);
}

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import java.util.List;
import org.junit.rules.ExternalResource;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
/**
* Base {@link ExternalResource} for launching a Spring Boot application as part of a
@ -74,7 +75,7 @@ abstract class AbstractApplicationLauncher extends ExternalResource {
arguments.add(System.getProperty("java.home") + "/bin/java");
arguments.addAll(getArguments(archive));
ProcessBuilder processBuilder = new ProcessBuilder(
arguments.toArray(new String[arguments.size()]));
StringUtils.toStringArray(arguments));
processBuilder.redirectOutput(Redirect.INHERIT);
processBuilder.redirectError(Redirect.INHERIT);
if (workingDirectory != null) {

@ -1,5 +1,5 @@
/*
* 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");
* you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ public abstract class AbstractEmbeddedServletContainerIntegrationTests {
parameters.addAll(createParameters(packaging, "jetty", applicationLaunchers));
parameters.addAll(createParameters(packaging, "tomcat", 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,

Loading…
Cancel
Save