Consistent use of StringUtils.toStringArray

(cherry picked from commit 6d11b40)
This commit is contained in:
Juergen Hoeller 2018-02-16 19:48:43 +01:00
parent c198138d4e
commit d7cab23e6d
29 changed files with 102 additions and 113 deletions

View File

@ -551,7 +551,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
results.add(beanName); results.add(beanName);
} }
} }
return results.toArray(new String[results.size()]); return StringUtils.toStringArray(results);
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -502,7 +502,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
if (dependenciesForBean == null) { if (dependenciesForBean == null) {
return new String[0]; return new String[0];
} }
return dependenciesForBean.toArray(new String[dependenciesForBean.size()]); return StringUtils.toStringArray(dependenciesForBean);
} }
public void destroySingletons() { public void destroySingletons() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -338,7 +338,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
results.add(beanName); results.add(beanName);
} }
} }
return results.toArray(new String[results.size()]); return StringUtils.toStringArray(results);
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.IndexedTestBean; import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean; import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*; import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
@ -838,12 +839,12 @@ public class PropertyResourceConfigurerTests {
@Override @Override
protected String[] keysSpi() throws BackingStoreException { protected String[] keysSpi() throws BackingStoreException {
return values.keySet().toArray(new String[values.size()]); return StringUtils.toStringArray(values.keySet());
} }
@Override @Override
protected String[] childrenNamesSpi() throws BackingStoreException { protected String[] childrenNamesSpi() throws BackingStoreException {
return children.keySet().toArray(new String[values.size()]); return StringUtils.toStringArray(children.keySet());
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -62,8 +62,7 @@ public class TestCompiler {
public TestCompilationTask getTask(Class<?>... types) { public TestCompilationTask getTask(Class<?>... types) {
List<String> names = Arrays.stream(types).map(Class::getName) List<String> names = Arrays.stream(types).map(Class::getName).collect(Collectors.toList());
.collect(Collectors.toList());
return getTask(names.toArray(new String[names.size()])); return getTask(names.toArray(new String[names.size()]));
} }
@ -72,10 +71,9 @@ public class TestCompiler {
return getTask(javaFileObjects); return getTask(javaFileObjects);
} }
private TestCompilationTask getTask( private TestCompilationTask getTask(Iterable<? extends JavaFileObject> javaFileObjects) {
Iterable<? extends JavaFileObject> javaFileObjects) { return new TestCompilationTask(
return new TestCompilationTask(this.compiler.getTask(null, this.fileManager, null, this.compiler.getTask(null, this.fileManager, null, null, null, javaFileObjects));
null, null, javaFileObjects));
} }
public File getOutputLocation() { public File getOutputLocation() {
@ -120,7 +118,6 @@ public class TestCompiler {
throw new IllegalStateException("Compilation failed"); throw new IllegalStateException("Compilation failed");
} }
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector; import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AutoProxyRegistrar; import org.springframework.context.annotation.AutoProxyRegistrar;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/** /**
* Selects which implementation of {@link AbstractCachingConfiguration} should be used * Selects which implementation of {@link AbstractCachingConfiguration} should be used
@ -84,7 +85,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) { if (jsr107Present && jcacheImplPresent) {
result.add(PROXY_JCACHE_CONFIGURATION_CLASS); result.add(PROXY_JCACHE_CONFIGURATION_CLASS);
} }
return result.toArray(new String[result.size()]); return StringUtils.toStringArray(result);
} }
/** /**
@ -97,7 +98,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) { if (jsr107Present && jcacheImplPresent) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME); result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
} }
return result.toArray(new String[result.size()]); return StringUtils.toStringArray(result);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* Support class for {@link AttributeAccessor AttributeAccessors}, providing * Support class for {@link AttributeAccessor AttributeAccessors}, providing
@ -73,7 +74,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser
@Override @Override
public String[] attributeNames() { public String[] attributeNames() {
return this.attributes.keySet().toArray(new String[this.attributes.size()]); return StringUtils.toStringArray(this.attributes.keySet());
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.core.env;
import java.util.List; import java.util.List;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/** /**
* {@link CommandLinePropertySource} implementation backed by a simple String array. * {@link CommandLinePropertySource} implementation backed by a simple String array.
@ -102,7 +103,7 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource<C
*/ */
@Override @Override
public String[] getPropertyNames() { public String[] getPropertyNames() {
return source.getOptionNames().toArray(new String[source.getOptionNames().size()]); return StringUtils.toStringArray(this.source.getOptionNames());
} }
@Override @Override

View File

@ -26,6 +26,7 @@ import org.springframework.beans.PropertyAccessor;
import org.springframework.beans.PropertyAccessorFactory; import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.jdbc.core.StatementCreatorUtils; import org.springframework.jdbc.core.StatementCreatorUtils;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/** /**
* {@link SqlParameterSource} implementation that obtains parameter values * {@link SqlParameterSource} implementation that obtains parameter values
@ -107,7 +108,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
names.add(pd.getName()); names.add(pd.getName());
} }
} }
this.propertyNames = names.toArray(new String[names.size()]); this.propertyNames = StringUtils.toStringArray(names);
} }
return this.propertyNames; return this.propertyNames;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -228,7 +229,7 @@ public class JdbcTemplateTests {
this.list.add(rs.getString(1)); this.list.add(rs.getString(1));
} }
public String[] getStrings() { public String[] getStrings() {
return this.list.toArray(new String[this.list.size()]); return StringUtils.toStringArray(this.list);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,6 +39,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.Customer; import org.springframework.jdbc.Customer;
import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -764,9 +765,7 @@ public class SqlQueryTests {
} }
public String[] run() { public String[] run() {
List<String> list = execute(); return StringUtils.toStringArray(execute());
String[] results = list.toArray(new String[list.size()]);
return results;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.StubMessageChannel; import org.springframework.messaging.StubMessageChannel;
import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -33,7 +34,6 @@ import static org.junit.Assert.*;
*/ */
public class StompBrokerRelayRegistrationTests { public class StompBrokerRelayRegistrationTests {
@Test @Test
public void test() { public void test() {
@ -52,7 +52,7 @@ public class StompBrokerRelayRegistrationTests {
StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel()); StompBrokerRelayMessageHandler handler = registration.getMessageHandler(new StubMessageChannel());
assertArrayEquals(prefixes, handler.getDestinationPrefixes().toArray(new String[2])); assertArrayEquals(prefixes, StringUtils.toStringArray(handler.getDestinationPrefixes()));
assertEquals("clientlogin", handler.getClientLogin()); assertEquals("clientlogin", handler.getClientLogin());
assertEquals("clientpasscode", handler.getClientPasscode()); assertEquals("clientpasscode", handler.getClientPasscode());
assertEquals("syslogin", handler.getSystemLogin()); assertEquals("syslogin", handler.getSystemLogin());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@ import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface. * Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -168,7 +169,7 @@ public class MockHttpSession implements HttpSession {
@Override @Override
public String[] getValueNames() { public String[] getValueNames() {
assertIsValid(); assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]); return StringUtils.toStringArray(this.attributes.keySet());
} }
@Override @Override

View File

@ -54,9 +54,6 @@ public abstract class ModelAndViewAssert {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) { public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class<T> expectedType) {
if (mav == null) {
fail("ModelAndView is null");
}
Map<String, Object> model = mav.getModel(); Map<String, Object> model = mav.getModel();
Object obj = model.get(modelName); Object obj = model.get(modelName);
if (obj == null) { if (obj == null) {
@ -75,7 +72,6 @@ public abstract class ModelAndViewAssert {
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) { public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
assertTrue("ModelAndView is null", mav != null);
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class); List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" + assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
expectedList.size() + "'", expectedList.size() == modelList.size()); expectedList.size() + "'", expectedList.size() == modelList.size());
@ -89,9 +85,6 @@ public abstract class ModelAndViewAssert {
* @param modelName name of the object to add to the model (never {@code null}) * @param modelName name of the object to add to the model (never {@code null})
*/ */
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) { public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
if (mav == null) {
fail("ModelAndView is null");
}
Map<String, Object> model = mav.getModel(); Map<String, Object> model = mav.getModel();
assertTrue("Model attribute with name '" + modelName + "' is not available", model.containsKey(modelName)); assertTrue("Model attribute with name '" + modelName + "' is not available", model.containsKey(modelName));
} }
@ -104,7 +97,6 @@ public abstract class ModelAndViewAssert {
* @param expectedValue the model value * @param expectedValue the model value
*/ */
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) { public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
assertTrue("ModelAndView is null", mav != null);
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class); Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
assertTrue("Model value with name '" + modelName + "' is not the same as the expected value which was '" + assertTrue("Model value with name '" + modelName + "' is not the same as the expected value which was '" +
expectedValue + "'", modelValue.equals(expectedValue)); expectedValue + "'", modelValue.equals(expectedValue));
@ -117,9 +109,6 @@ public abstract class ModelAndViewAssert {
* @param expectedModel the expected model * @param expectedModel the expected model
*/ */
public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) { public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
if (mav == null) {
fail("ModelAndView is null");
}
Map<String, Object> model = mav.getModel(); Map<String, Object> model = mav.getModel();
if (!model.keySet().equals(expectedModel.keySet())) { if (!model.keySet().equals(expectedModel.keySet())) {
@ -157,9 +146,7 @@ public abstract class ModelAndViewAssert {
public static void assertSortAndCompareListModelAttribute( public static void assertSortAndCompareListModelAttribute(
ModelAndView mav, String modelName, List expectedList, Comparator comparator) { ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
assertTrue("ModelAndView is null", mav != null);
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class); List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" + assertTrue("Size of model list is '" + modelList.size() + "' while size of expected list is '" +
expectedList.size() + "'", expectedList.size() == modelList.size()); expectedList.size() + "'", expectedList.size() == modelList.size());
@ -177,9 +164,6 @@ public abstract class ModelAndViewAssert {
* @param expectedName the name of the model value * @param expectedName the name of the model value
*/ */
public static void assertViewName(ModelAndView mav, String expectedName) { public static void assertViewName(ModelAndView mav, String expectedName) {
if (mav == null) {
fail("ModelAndView is null");
}
assertTrue("View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'", assertTrue("View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'",
ObjectUtils.nullSafeEquals(expectedName, mav.getViewName())); ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -221,7 +221,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
logger.info("Scanning base packages: [" + logger.info("Scanning base packages: [" +
StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]"); StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
} }
scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()])); scanner.scan(StringUtils.toStringArray(this.basePackages));
} }
String[] configLocations = getConfigLocations(); String[] configLocations = getConfigLocations();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
/** /**
* {@link javax.servlet.Filter} that makes form encoded data available through * {@link javax.servlet.Filter} that makes form encoded data available through
@ -170,13 +171,13 @@ public class HttpPutFormContentFilter extends OncePerRequestFilter {
return parameterValues; return parameterValues;
} }
if (parameterValues == null || getQueryString() == null) { if (parameterValues == null || getQueryString() == null) {
return formParam.toArray(new String[formParam.size()]); return StringUtils.toStringArray(formParam);
} }
else { else {
List<String> result = new ArrayList<>(parameterValues.length + formParam.size()); List<String> result = new ArrayList<>(parameterValues.length + formParam.size());
result.addAll(Arrays.asList(parameterValues)); result.addAll(Arrays.asList(parameterValues));
result.addAll(formParam); result.addAll(formParam);
return result.toArray(new String[result.size()]); return StringUtils.toStringArray(result);
} }
} }
} }

View File

@ -27,6 +27,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* {@code UriBuilderFactory} that relies on {@link UriComponentsBuilder} for * {@code UriBuilderFactory} that relies on {@link UriComponentsBuilder} for
@ -216,7 +217,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) { private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uriTemplate); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uriTemplate);
UriComponents uriComponents = uriComponentsBuilder.build(); UriComponents uriComponents = uriComponentsBuilder.build();
UriComponentsBuilder result = (uriComponents.getHost() == null ? UriComponentsBuilder result = (uriComponents.getHost() == null ?
baseUri.cloneBuilder().uriComponents(uriComponents) : uriComponentsBuilder); baseUri.cloneBuilder().uriComponents(uriComponents) : uriComponentsBuilder);
@ -224,10 +224,8 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
UriComponents uric = result.build(); UriComponents uric = result.build();
String path = uric.getPath(); String path = uric.getPath();
List<String> pathSegments = uric.getPathSegments(); List<String> pathSegments = uric.getPathSegments();
result.replacePath(null); result.replacePath(null);
result.pathSegment(pathSegments.toArray(new String[0])); result.pathSegment(StringUtils.toStringArray(pathSegments));
if (path != null && path.endsWith("/")) { if (path != null && path.endsWith("/")) {
result.path("/"); result.path("/");
} }

View File

@ -792,7 +792,7 @@ final class HierarchicalUriComponents extends UriComponents {
@Override @Override
public void copyToUriComponentsBuilder(UriComponentsBuilder builder) { public void copyToUriComponentsBuilder(UriComponentsBuilder builder) {
builder.pathSegment(getPathSegments().toArray(new String[getPathSegments().size()])); builder.pathSegment(StringUtils.toStringArray(getPathSegments()));
} }
@Override @Override

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/** /**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface. * Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -167,7 +168,7 @@ public class MockHttpSession implements HttpSession {
@Override @Override
public String[] getValueNames() { public String[] getValueNames() {
assertIsValid(); assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]); return StringUtils.toStringArray(this.attributes.keySet());
} }
@Override @Override

View File

@ -134,7 +134,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
prefixedPatterns.add(versionPrefix + pattern); prefixedPatterns.add(versionPrefix + pattern);
} }
} }
return addVersionStrategy(new FixedVersionStrategy(version), prefixedPatterns.toArray(new String[0])); return addVersionStrategy(new FixedVersionStrategy(version), StringUtils.toStringArray(prefixedPatterns));
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils; import org.springframework.util.xml.DomUtils;
/** /**
@ -60,7 +61,7 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean
if (locations.isEmpty()) { if (locations.isEmpty()) {
locations.add("/WEB-INF/"); locations.add("/WEB-INF/");
} }
builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()])); builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils; import org.springframework.util.xml.DomUtils;
/** /**
@ -58,7 +59,7 @@ public class ScriptTemplateConfigurerBeanDefinitionParser extends AbstractSimple
for (Element childElement : childElements) { for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location")); locations.add(childElement.getAttribute("location"));
} }
builder.addPropertyValue("scripts", locations.toArray(new String[locations.size()])); builder.addPropertyValue("scripts", StringUtils.toStringArray(locations));
} }
builder.addPropertyValue("engineName", element.getAttribute("engine-name")); builder.addPropertyValue("engineName", element.getAttribute("engine-name"));
if (element.hasAttribute("render-object")) { if (element.hasAttribute("render-object")) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext; import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils; import org.springframework.util.xml.DomUtils;
/** /**
@ -58,7 +59,7 @@ public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefin
for (Element childElement : childElements) { for (Element childElement : childElements) {
locations.add(childElement.getAttribute("location")); locations.add(childElement.getAttribute("location"));
} }
builder.addPropertyValue("definitions", locations.toArray(new String[locations.size()])); builder.addPropertyValue("definitions", StringUtils.toStringArray(locations));
} }
if (element.hasAttribute("check-refresh")) { if (element.hasAttribute("check-refresh")) {
builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh")); builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,13 +49,14 @@ public class InterceptorRegistration {
/** /**
* Creates an {@link InterceptorRegistration} instance. * Create an {@link InterceptorRegistration} instance.
*/ */
public InterceptorRegistration(HandlerInterceptor interceptor) { public InterceptorRegistration(HandlerInterceptor interceptor) {
Assert.notNull(interceptor, "Interceptor is required"); Assert.notNull(interceptor, "Interceptor is required");
this.interceptor = interceptor; this.interceptor = interceptor;
} }
/** /**
* Add URL patterns to which the registered interceptor should apply to. * Add URL patterns to which the registered interceptor should apply to.
*/ */
@ -116,9 +117,10 @@ public class InterceptorRegistration {
return this.order; return this.order;
} }
/** /**
* Returns the underlying interceptor. If URL patterns are provided the returned type is * Build the underlying interceptor. If URL patterns are provided, the returned
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}. * type is {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
*/ */
protected Object getInterceptor() { protected Object getInterceptor() {
if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) { if (this.includePatterns.isEmpty() && this.excludePatterns.isEmpty()) {
@ -128,11 +130,9 @@ public class InterceptorRegistration {
String[] include = StringUtils.toStringArray(this.includePatterns); String[] include = StringUtils.toStringArray(this.includePatterns);
String[] exclude = StringUtils.toStringArray(this.excludePatterns); String[] exclude = StringUtils.toStringArray(this.excludePatterns);
MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor); MappedInterceptor mappedInterceptor = new MappedInterceptor(include, exclude, this.interceptor);
if (this.pathMatcher != null) { if (this.pathMatcher != null) {
mappedInterceptor.setPathMatcher(this.pathMatcher); mappedInterceptor.setPathMatcher(this.pathMatcher);
} }
return mappedInterceptor; return mappedInterceptor;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,11 +32,10 @@ import org.springframework.web.servlet.ModelAndView;
* Also provides matching logic to test if the interceptor applies to a given request path. * Also provides matching logic to test if the interceptor applies to a given request path.
* *
* <p>A MappedInterceptor can be registered directly with any * <p>A MappedInterceptor can be registered directly with any
* {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping * {@link org.springframework.web.servlet.handler.AbstractHandlerMethodMapping}.
* AbstractHandlerMethodMapping}. Furthermore, beans of type MappedInterceptor * Furthermore, beans of type {@code MappedInterceptor} are automatically detected by
* are automatically detected by {@code AbstractHandlerMethodMapping} (including * {@code AbstractHandlerMethodMapping} (including ancestor ApplicationContext's) which
* ancestor ApplicationContext's) which effectively means the interceptor is * effectively means the interceptor is registered "globally" with all handler mappings.
* registered "globally" with all handler mappings.
* *
* @author Keith Donald * @author Keith Donald
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
@ -59,7 +58,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param interceptor the HandlerInterceptor instance to map to the given patterns * @param interceptor the HandlerInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(@Nullable String[] includePatterns, HandlerInterceptor interceptor) { public MappedInterceptor(@Nullable String[] includePatterns, HandlerInterceptor interceptor) {
@ -68,8 +67,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param excludePatterns the path patterns to exclude * @param excludePatterns the path patterns to exclude (empty for no specific excludes)
* @param interceptor the HandlerInterceptor instance to map to the given patterns * @param interceptor the HandlerInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns,
@ -83,7 +82,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param interceptor the WebRequestInterceptor instance to map to the given patterns * @param interceptor the WebRequestInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(@Nullable String[] includePatterns, WebRequestInterceptor interceptor) { public MappedInterceptor(@Nullable String[] includePatterns, WebRequestInterceptor interceptor) {
@ -92,7 +91,8 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Create a new MappedInterceptor instance. * Create a new MappedInterceptor instance.
* @param includePatterns the path patterns to map with a {@code null} value matching to all paths * @param includePatterns the path patterns to map (empty for matching to all paths)
* @param excludePatterns the path patterns to exclude (empty for no specific excludes)
* @param interceptor the WebRequestInterceptor instance to map to the given patterns * @param interceptor the WebRequestInterceptor instance to map to the given patterns
*/ */
public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns,
@ -103,11 +103,11 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Configure a PathMatcher to use with this MappedInterceptor instead of the * Configure a PathMatcher to use with this MappedInterceptor instead of the one passed
* one passed by default to the {@link #matches(String, org.springframework.util.PathMatcher)} * by default to the {@link #matches(String, org.springframework.util.PathMatcher)} method.
* method. This is an advanced property that is only required when using custom * <p>This is an advanced property that is only required when using custom PathMatcher
* PathMatcher implementations that support mapping metadata other than the * implementations that support mapping metadata other than the Ant-style path patterns
* Ant-style path patterns supported by default. * supported by default.
*/ */
public void setPathMatcher(@Nullable PathMatcher pathMatcher) { public void setPathMatcher(@Nullable PathMatcher pathMatcher) {
this.pathMatcher = pathMatcher; this.pathMatcher = pathMatcher;
@ -130,7 +130,7 @@ public final class MappedInterceptor implements HandlerInterceptor {
} }
/** /**
* The actual Interceptor reference. * The actual {@link HandlerInterceptor} reference.
*/ */
public HandlerInterceptor getInterceptor() { public HandlerInterceptor getInterceptor() {
return this.interceptor; return this.interceptor;
@ -138,13 +138,14 @@ public final class MappedInterceptor implements HandlerInterceptor {
/** /**
* Returns {@code true} if the interceptor applies to the given request path. * Determine a match for the given lookup path.
* @param lookupPath the current request path * @param lookupPath the current request path
* @param pathMatcher a path matcher for path pattern matching * @param pathMatcher a path matcher for path pattern matching
* @return {@code true} if the interceptor applies to the given request path
*/ */
public boolean matches(String lookupPath, PathMatcher pathMatcher) { public boolean matches(String lookupPath, PathMatcher pathMatcher) {
PathMatcher pathMatcherToUse = (this.pathMatcher != null) ? this.pathMatcher : pathMatcher; PathMatcher pathMatcherToUse = (this.pathMatcher != null ? this.pathMatcher : pathMatcher);
if (this.excludePatterns != null) { if (!ObjectUtils.isEmpty(this.excludePatterns)) {
for (String pattern : this.excludePatterns) { for (String pattern : this.excludePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) { if (pathMatcherToUse.match(pattern, lookupPath)) {
return false; return false;
@ -154,7 +155,6 @@ public final class MappedInterceptor implements HandlerInterceptor {
if (ObjectUtils.isEmpty(this.includePatterns)) { if (ObjectUtils.isEmpty(this.includePatterns)) {
return true; return true;
} }
else {
for (String pattern : this.includePatterns) { for (String pattern : this.includePatterns) {
if (pathMatcherToUse.match(pattern, lookupPath)) { if (pathMatcherToUse.match(pattern, lookupPath)) {
return true; return true;
@ -162,7 +162,6 @@ public final class MappedInterceptor implements HandlerInterceptor {
} }
return false; return false;
} }
}
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)

View File

@ -133,7 +133,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
prefixedPatterns.add(versionPrefix + pattern); prefixedPatterns.add(versionPrefix + pattern);
} }
} }
return addVersionStrategy(new FixedVersionStrategy(version), prefixedPatterns.toArray(new String[0])); return addVersionStrategy(new FixedVersionStrategy(version), StringUtils.toStringArray(prefixedPatterns));
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeHandler; import org.springframework.web.socket.server.HandshakeHandler;
import org.springframework.web.socket.server.HandshakeInterceptor; import org.springframework.web.socket.server.HandshakeInterceptor;
@ -65,7 +66,6 @@ public abstract class AbstractWebSocketHandlerRegistration<M> implements WebSock
/** /**
* Deprecated constructor with a TaskScheduler. * Deprecated constructor with a TaskScheduler.
*
* @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until * @deprecated as of 5.0 a TaskScheduler is not provided upfront, not until
* it is obvious that it is needed, see {@link #getSockJsServiceRegistration()}. * it is obvious that it is needed, see {@link #getSockJsServiceRegistration()}.
*/ */
@ -126,8 +126,7 @@ public abstract class AbstractWebSocketHandlerRegistration<M> implements WebSock
this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler); this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler);
} }
if (!this.allowedOrigins.isEmpty()) { if (!this.allowedOrigins.isEmpty()) {
this.sockJsServiceRegistration.setAllowedOrigins( this.sockJsServiceRegistration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins));
this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
} }
return this.sockJsServiceRegistration; return this.sockJsServiceRegistration;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.HttpRequestHandler; import org.springframework.web.HttpRequestHandler;
import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeHandler; import org.springframework.web.socket.server.HandshakeHandler;
@ -110,7 +111,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.registration.setTransportHandlerOverrides(handler); this.registration.setTransportHandlerOverrides(handler);
} }
if (!this.allowedOrigins.isEmpty()) { if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()])); this.registration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins));
} }
return this.registration; return this.registration;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -182,7 +182,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
* Return the list of supported sub-protocols. * Return the list of supported sub-protocols.
*/ */
public String[] getSupportedProtocols() { public String[] getSupportedProtocols() {
return this.supportedProtocols.toArray(new String[this.supportedProtocols.size()]); return StringUtils.toStringArray(this.supportedProtocols);
} }
@Override @Override
@ -403,8 +403,8 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
* @return the user for the WebSocket session, or {@code null} if not available * @return the user for the WebSocket session, or {@code null} if not available
*/ */
@Nullable @Nullable
protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, protected Principal determineUser(
Map<String, Object> attributes) { ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
return request.getPrincipal(); return request.getPrincipal();
} }