Browse Source

Consistent use of StringUtils.toStringArray

(cherry picked from commit 6d11b40)
pull/1691/head
Juergen Hoeller 8 years ago
parent
commit
d7cab23e6d
  1. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  2. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
  3. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
  4. 7
      spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java
  5. 13
      spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java
  6. 7
      spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java
  7. 5
      spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java
  8. 5
      spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java
  9. 3
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java
  10. 5
      spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java
  11. 7
      spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java
  12. 6
      spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java
  13. 5
      spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java
  14. 16
      spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java
  15. 4
      spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java
  16. 7
      spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java
  17. 6
      spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java
  18. 2
      spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java
  19. 5
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
  20. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java
  21. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java
  22. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java
  23. 5
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java
  24. 12
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java
  25. 51
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java
  26. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java
  27. 7
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java
  28. 5
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java
  29. 8
      spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java

2
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

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

4
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -502,7 +502,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements @@ -502,7 +502,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
if (dependenciesForBean == null) {
return new String[0];
}
return dependenciesForBean.toArray(new String[dependenciesForBean.size()]);
return StringUtils.toStringArray(dependenciesForBean);
}
public void destroySingletons() {

4
spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -338,7 +338,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { @@ -338,7 +338,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
results.add(beanName);
}
}
return results.toArray(new String[results.size()]);
return StringUtils.toStringArray(results);
}
@Override

7
spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -42,6 +42,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition; @@ -42,6 +42,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
@ -838,12 +839,12 @@ public class PropertyResourceConfigurerTests { @@ -838,12 +839,12 @@ public class PropertyResourceConfigurerTests {
@Override
protected String[] keysSpi() throws BackingStoreException {
return values.keySet().toArray(new String[values.size()]);
return StringUtils.toStringArray(values.keySet());
}
@Override
protected String[] childrenNamesSpi() throws BackingStoreException {
return children.keySet().toArray(new String[values.size()]);
return StringUtils.toStringArray(children.keySet());
}
@Override

13
spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java

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

7
spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java vendored

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.context.annotation.AdviceMode; @@ -23,6 +23,7 @@ import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.context.annotation.AutoProxyRegistrar;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* Selects which implementation of {@link AbstractCachingConfiguration} should be used
@ -84,7 +85,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl @@ -84,7 +85,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) {
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 @@ -97,7 +98,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
if (jsr107Present && jcacheImplPresent) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
}
return result.toArray(new String[result.size()]);
return StringUtils.toStringArray(result);
}
}

5
spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import java.util.Map; @@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Support class for {@link AttributeAccessor AttributeAccessors}, providing
@ -73,7 +74,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser @@ -73,7 +74,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser
@Override
public String[] attributeNames() {
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}

5
spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java vendored

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.core.env; @@ -19,6 +19,7 @@ package org.springframework.core.env;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
* {@link CommandLinePropertySource} implementation backed by a simple String array.
@ -102,7 +103,7 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource<C @@ -102,7 +103,7 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource<C
*/
@Override
public String[] getPropertyNames() {
return source.getOptionNames().toArray(new String[source.getOptionNames().size()]);
return StringUtils.toStringArray(this.source.getOptionNames());
}
@Override

3
spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java

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

5
spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource; @@ -50,6 +50,7 @@ import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@ -228,7 +229,7 @@ public class JdbcTemplateTests { @@ -228,7 +229,7 @@ public class JdbcTemplateTests {
this.list.add(rs.getString(1));
}
public String[] getStrings() {
return this.list.toArray(new String[this.list.size()]);
return StringUtils.toStringArray(this.list);
}
}

7
spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -39,6 +39,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -39,6 +39,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.Customer;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@ -764,9 +765,7 @@ public class SqlQueryTests { @@ -764,9 +765,7 @@ public class SqlQueryTests {
}
public String[] run() {
List<String> list = execute();
String[] results = list.toArray(new String[list.size()]);
return results;
return StringUtils.toStringArray(execute());
}
}

6
spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.springframework.messaging.MessageChannel; @@ -22,6 +22,7 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.StubMessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.util.StringUtils;
import static org.junit.Assert.*;
@ -33,7 +34,6 @@ import static org.junit.Assert.*; @@ -33,7 +34,6 @@ import static org.junit.Assert.*;
*/
public class StompBrokerRelayRegistrationTests {
@Test
public void test() {
@ -52,7 +52,7 @@ public class StompBrokerRelayRegistrationTests { @@ -52,7 +52,7 @@ public class StompBrokerRelayRegistrationTests {
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("clientpasscode", handler.getClientPasscode());
assertEquals("syslogin", handler.getSystemLogin());

5
spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@ import javax.servlet.http.HttpSessionBindingListener; @@ -31,6 +31,7 @@ import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -168,7 +169,7 @@ public class MockHttpSession implements HttpSession { @@ -168,7 +169,7 @@ public class MockHttpSession implements HttpSession {
@Override
public String[] getValueNames() {
assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}
@Override

16
spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java

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

4
spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -221,7 +221,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe @@ -221,7 +221,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
logger.info("Scanning base packages: [" +
StringUtils.collectionToCommaDelimitedString(this.basePackages) + "]");
}
scanner.scan(this.basePackages.toArray(new String[this.basePackages.size()]));
scanner.scan(StringUtils.toStringArray(this.basePackages));
}
String[] configLocations = getConfigLocations();

7
spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java

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

6
spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java

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

2
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java

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

5
spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import javax.servlet.http.HttpSessionBindingEvent; @@ -30,6 +30,7 @@ import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
@ -167,7 +168,7 @@ public class MockHttpSession implements HttpSession { @@ -167,7 +168,7 @@ public class MockHttpSession implements HttpSession {
@Override
public String[] getValueNames() {
assertIsValid();
return this.attributes.keySet().toArray(new String[this.attributes.size()]);
return StringUtils.toStringArray(this.attributes.keySet());
}
@Override

2
spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

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

5
spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -60,7 +61,7 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean @@ -60,7 +61,7 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean
if (locations.isEmpty()) {
locations.add("/WEB-INF/");
}
builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()]));
builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations));
}
}

5
spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -58,7 +59,7 @@ public class ScriptTemplateConfigurerBeanDefinitionParser extends AbstractSimple @@ -58,7 +59,7 @@ public class ScriptTemplateConfigurerBeanDefinitionParser extends AbstractSimple
for (Element childElement : childElements) {
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"));
if (element.hasAttribute("render-object")) {

5
spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@ -58,7 +59,7 @@ public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefin @@ -58,7 +59,7 @@ public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefin
for (Element childElement : childElements) {
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")) {
builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));

12
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java

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

51
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java

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

2
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

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

7
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java

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

5
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.util.Assert; @@ -26,6 +26,7 @@ import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.HandshakeHandler;
@ -110,7 +111,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE @@ -110,7 +111,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.registration.setTransportHandlerOverrides(handler);
}
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;
}

8
spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java

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

Loading…
Cancel
Save