diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextConfigurationImportSelector.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextConfigurationImportSelector.java index d665e37c47..87e4aba942 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextConfigurationImportSelector.java @@ -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 getConfigurations() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextFactory.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextFactory.java index ef237ea21e..816ec9c432 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextFactory.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementContextFactory.java @@ -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> 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; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/EndpointAutoConfigurationClasses.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/EndpointAutoConfigurationClasses.java index 38f3e5d39a..4cb28b3570 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/EndpointAutoConfigurationClasses.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/EndpointAutoConfigurationClasses.java @@ -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() { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchHealthIndicator.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchHealthIndicator.java index 84477e07b3..2ae834524c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchHealthIndicator.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/elasticsearch/ElasticsearchHealthIndicator.java @@ -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 indices) { - this(client, responseTimeout, (indices == null ? null - : indices.toArray(new String[indices.size()]))); + this(client, responseTimeout, + (indices == null ? null : StringUtils.toStringArray(indices))); } /** diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java index 2cc6d9ef17..e48c6f15ce 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/jersey/JerseyEndpointResourceFactory.java @@ -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 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(); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java index e212595461..1baeb06655 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/reactive/AbstractWebFluxEndpointHandlerMapping.java @@ -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 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); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java index dd0e7b60b5..8052cd020c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/servlet/AbstractWebMvcEndpointHandlerMapping.java @@ -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 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); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java index d5450dcbee..e717b99533 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpointTests.java @@ -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())); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscovererTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscovererTests.java index 2f381081c8..9d99cd2fa2 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscovererTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscovererTests.java @@ -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) { diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java index b0076658f9..a5159a378a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/JerseyEndpointsRunner.java @@ -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> 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; } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java index 8735d05141..73c2ee3916 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebFluxEndpointsRunner.java @@ -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> 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; } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java index da424a1995..2d61ab175b 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/test/WebMvcEndpointRunner.java @@ -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> 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; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index 8b1ebe1ef0..4b2c457f87 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -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 filter(List 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()) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java index 6a62208adb..2e6ae495e5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationPackages.java @@ -114,7 +114,7 @@ public abstract class AutoConfigurationPackages { Set merged = new LinkedHashSet<>(); merged.addAll(Arrays.asList(existing)); merged.addAll(Arrays.asList(packageNames)); - return merged.toArray(new String[merged.size()]); + return StringUtils.toStringArray(merged); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java index ed92bfc707..d8fa3fcd4d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java @@ -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); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index d8f2e4d933..bfc9b4776a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -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(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java index a6ceb07d68..7409379d21 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.java @@ -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 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java index 0cf5002585..f536581e68 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/domain/EntityScanPackages.java @@ -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 merged = new LinkedHashSet<>(); merged.addAll(Arrays.asList(existing)); merged.addAll(packageNames); - return merged.toArray(new String[merged.size()]); + return StringUtils.toStringArray(merged); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index ba151099ee..e2a37fc846 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -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 locations) { - return resolveLocations(locations.toArray(new String[locations.size()])); + return resolveLocations(StringUtils.toStringArray(locations)); } public String[] resolveLocations(String[] locations) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index a1125c81ba..5280a4b6dc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -337,8 +337,7 @@ public class JacksonAutoConfiguration { private void configureModules(Jackson2ObjectMapperBuilder builder) { Collection 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) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java index 92e60a599c..c759660dbc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java @@ -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( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index 9cfa4817d6..40e64d931d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -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 mappingResources = this.properties.getMappingResources(); return (!ObjectUtils.isEmpty(mappingResources) - ? mappingResources.toArray(new String[mappingResources.size()]) : null); + ? StringUtils.toStringArray(mappingResources) : null); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java index 4a31f1aa0e..95909b46da 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java @@ -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(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfiguration.java index 6c74c6b5d8..a5f72f5ce4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/ReactiveUserDetailsServiceAutoConfiguration.java @@ -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 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, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.java index 24feffcfa6..8da67561d1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/UserDetailsServiceAutoConfiguration.java @@ -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 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, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index 4c7a5e2335..a1cf193045 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -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); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java index 33c62c73c1..a873a20c7a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndImperativeRepositoriesAutoConfigurationTests.java @@ -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); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MixedMongoRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MixedMongoRepositoriesAutoConfigurationTests.java index 6dcc70c4c5..d435901437 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MixedMongoRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MixedMongoRepositoriesAutoConfigurationTests.java @@ -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); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveAndBlockingRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveAndBlockingRepositoriesAutoConfigurationTests.java index dde4b3a002..279b22815f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveAndBlockingRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveAndBlockingRepositoriesAutoConfigurationTests.java @@ -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); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java index eb0ac7222a..9dd159547f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java @@ -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 void assertDataSource(Class expectedType, List hiddenPackages, Consumer 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); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java index bdc6d82365..d15e44249c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQAutoConfigurationTests.java @@ -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(); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java index 0e41559e78..6b32f333c8 100755 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java @@ -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) diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java index 00998f5645..23aff7c552 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java @@ -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]); } } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java index bfea4c4cbc..29b23807d1 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java @@ -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 { } rtn.add(arg); } - return rtn.toArray(new String[rtn.size()]); + return StringUtils.toStringArray(rtn); } /** diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/SourceOptions.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/SourceOptions.java index 0d9bd95acb..172fa598b9 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/SourceOptions.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/options/SourceOptions.java @@ -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 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); } } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java index e41c221bbc..f561e79a0c 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/RunProcessCommand.java @@ -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 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; } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java index 7b84789ea3..76ad2d5305 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyManagementBomTransformation.java @@ -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> 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 { diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java index 4f2c4accc8..5e16696e9e 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoader.java @@ -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 urls) { diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 3b1092ce14..462f48aa71 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -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") diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java index e92dec0a78..27803cf69a 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java @@ -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); diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java index 172bce4bf8..af218ce23a 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java @@ -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 future = submitCommand(new RunCommand(), - updatedArgs.toArray(new String[updatedArgs.size()])); + StringUtils.toStringArray(updatedArgs)); this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS)); return getOutput(); } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java index f752f9c354..4f7c2dd50e 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsProperties.java @@ -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() { diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java index f098982d45..5b9f3960e4 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java @@ -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 { } public URL[] toArray() { - return this.urls.toArray(new URL[this.urls.size()]); + return this.urls.toArray(new URL[0]); } public List toList() { diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java index a1419e859e..37d8d07809 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ClassLoaderFilesResourcePatternResolver.java @@ -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 getAdditionalResources(String locationPattern) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 46053fbe3a..a29a5937b3 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -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); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java index b28c26a8ad..2b137a2296 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java @@ -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)); } } diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java index e09f543825..1acb71d7fb 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java @@ -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 properties) { @@ -187,9 +187,8 @@ public class SpringBootContextLoader extends AbstractContextLoader { private ConfigurationPropertySource convertToConfigurationPropertySource( List properties) { - String[] array = properties.toArray(new String[properties.size()]); - return new MapConfigurationPropertySource( - TestPropertySourceUtils.convertInlinedPropertiesToMap(array)); + return new MapConfigurationPropertySource(TestPropertySourceUtils + .convertInlinedPropertiesToMap(StringUtils.toStringArray(properties))); } /** diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java index 88e601b9a6..b0832ec625 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java @@ -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 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); diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockDefinition.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockDefinition.java index 36fadf227f..b6cb980db7 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockDefinition.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockDefinition.java @@ -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) { diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java index b683c7d8ca..1bafe45919 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoPostProcessor.java @@ -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) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java index cca814dedb..83b4c35403 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/TestJarFile.java @@ -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; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java index ba402225f4..9d7448017c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java @@ -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])); } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java index 65648e0fb7..3ec06db410 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java @@ -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); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index b093900a87..f1b011736f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -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 { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java index e08b6881af..d68857c986 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java @@ -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) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java index 6d37364e17..1280b88162 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunMojo.java @@ -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; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java index 3043923201..9a27ca8479 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java @@ -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) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java index 2af2909ad5..d18141734e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/runner/classpath/ModifiedClassPathRunner.java @@ -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 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 getAdditionalUrls(Class testClass) throws Exception { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 7766e454a3..11f0287e0e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -380,7 +380,7 @@ public class SpringApplication { // Load the sources Set 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 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) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java index befe6e1dc3..13ab654c41 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java @@ -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 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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java index b83c442e13..0bc991cad6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java @@ -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) { - List orderedConfigurations = new ArrayList<>(configurations); - orderedConfigurations.sort(COMPARATOR); - List collated = collate(orderedConfigurations); - return collated.stream().flatMap((c) -> c.getClasses().stream()) - .collect(Collectors.toCollection(LinkedHashSet::new)) - .toArray(new Class[0]); + List ordered = new ArrayList<>(configurations); + ordered.sort(COMPARATOR); + List collated = collate(ordered); + LinkedHashSet> classes = collated.stream() + .flatMap(Configurations::streamClasses) + .collect(Collectors.toCollection(LinkedHashSet::new)); + return ClassUtils.toClassArray(classes); + } + + private static Stream> streamClasses(Configurations configurations) { + return configurations.getClasses().stream(); } private static List collate( diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 140043333b..8c6e449d5a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -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 getSearchLocations() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java index 0c06260916..8007323eca 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.java @@ -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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index 7e900ed124..2720898291 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -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, diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java index efdd118608..2a1017a088 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java @@ -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); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosDependsOnBeanFactoryPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosDependsOnBeanFactoryPostProcessor.java index 23dffd28d3..d89f803422 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosDependsOnBeanFactoryPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jta/atomikos/AtomikosDependsOnBeanFactoryPostProcessor.java @@ -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 dependsOn = new LinkedHashSet<>(asList(bean.getDependsOn())); dependsOn.addAll(asList(transactionManagers)); - bean.setDependsOn(dependsOn.toArray(new String[dependsOn.size()])); + bean.setDependsOn(StringUtils.toStringArray(dependsOn)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index 231111d456..5af086173b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -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) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java index 078368015f..09a0d58957 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java @@ -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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index 430598eecc..cb5697ced8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -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]); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowCompressionConfigurer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowCompressionConfigurer.java index 0612976201..7111c0b45c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowCompressionConfigurer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowCompressionConfigurer.java @@ -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 { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index 8a992794ee..7e41286114 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -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) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java index 918bd58411..c93ee1b475 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java @@ -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, diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java index ed8573f952..37e1925a6f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java @@ -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)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java index 9d5b130a7e..733eb59792 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java @@ -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 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)); } } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java index 0a51f66422..7a8179cdab 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletRegistrationBean.java @@ -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 @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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java index 8f4252a405..11b6533326 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java @@ -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)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java index 92760c029a..00ce07717d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java @@ -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]); } /** diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java index b0a483daf1..1d9ae14aad 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SimpleMainTests.java @@ -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() { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java index 7d0a1877d9..58cf0d2a34 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java @@ -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); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java index d065a99927..2fb76b6b72 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java @@ -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 diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java index 3eae4b887d..2b6f355741 100644 --- a/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java +++ b/spring-boot-samples/spring-boot-sample-jooq/src/main/java/sample/jooq/JooqExamples.java @@ -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 list = this.jdbc.query(query.getSQL(), bind, new RowMapper() { @Override diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/JvmLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/JvmLauncher.java index a2e82af2c5..ef7f6c30c2 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/JvmLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/JvmLauncher.java @@ -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); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java index 4b803a7faf..c1d006e721 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java @@ -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) { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerIntegrationTests.java index 43666d8644..1a80d4b81a 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerIntegrationTests.java @@ -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 createParameters(String packaging, String container,