diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 7bddd96f384..ffec78d3f3a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -551,7 +551,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto results.add(beanName); } } - return results.toArray(new String[results.size()]); + return StringUtils.toStringArray(results); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java index bbafc653fa2..ee0296cfa65 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java @@ -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 if (dependenciesForBean == null) { return new String[0]; } - return dependenciesForBean.toArray(new String[dependenciesForBean.size()]); + return StringUtils.toStringArray(dependenciesForBean); } public void destroySingletons() { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java index 21a5318445c..193f190cb31 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java @@ -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 { results.add(beanName); } } - return results.toArray(new String[results.size()]); + return StringUtils.toStringArray(results); } @Override diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java index 9a02e5f5b36..23206d7c4b8 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java @@ -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; 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 { @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 diff --git a/spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java b/spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java index e55252125cc..08d2040435d 100644 --- a/spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java +++ b/spring-context-indexer/src/test/java/org/springframework/context/index/test/TestCompiler.java @@ -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 { public TestCompilationTask getTask(Class... types) { - List names = Arrays.stream(types).map(Class::getName) - .collect(Collectors.toList()); + List 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 { return getTask(javaFileObjects); } - private TestCompilationTask getTask( - Iterable javaFileObjects) { - return new TestCompilationTask(this.compiler.getTask(null, this.fileManager, null, - null, null, javaFileObjects)); + private TestCompilationTask getTask(Iterable javaFileObjects) { + return new TestCompilationTask( + this.compiler.getTask(null, this.fileManager, null, null, null, javaFileObjects)); } public File getOutputLocation() { @@ -120,7 +118,6 @@ public class TestCompiler { throw new IllegalStateException("Compilation failed"); } } - } } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java index bbe86bb7aa1..7d5149b08a8 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java @@ -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; 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 list = execute(); - String[] results = list.toArray(new String[list.size()]); - return results; + return StringUtils.toStringArray(execute()); } } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java index fcca909d3bc..b9fb84077bf 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistrationTests.java @@ -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; 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.*; */ public class StompBrokerRelayRegistrationTests { - @Test public void test() { @@ -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()); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java index ddc43bcac2d..4013854fd02 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java @@ -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; 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 { @Override public String[] getValueNames() { assertIsValid(); - return this.attributes.keySet().toArray(new String[this.attributes.size()]); + return StringUtils.toStringArray(this.attributes.keySet()); } @Override diff --git a/spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java b/spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java index 8fb715b5a2b..9510e718e50 100644 --- a/spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java @@ -54,9 +54,6 @@ public abstract class ModelAndViewAssert { */ @SuppressWarnings("unchecked") public static T assertAndReturnModelAttributeOfType(ModelAndView mav, String modelName, Class expectedType) { - if (mav == null) { - fail("ModelAndView is null"); - } Map model = mav.getModel(); Object obj = model.get(modelName); if (obj == null) { @@ -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 { * @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 model = mav.getModel(); 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 */ 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 { * @param expectedModel the expected model */ public static void assertModelAttributeValues(ModelAndView mav, Map expectedModel) { - if (mav == null) { - fail("ModelAndView is null"); - } Map model = mav.getModel(); if (!model.keySet().equals(expectedModel.keySet())) { @@ -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 { * @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())); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java index d34fd6e6d3b..615f6b7d255 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java @@ -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 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(); diff --git a/spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java b/spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java index c6bd492ef24..4e7dc13a81c 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/HttpPutFormContentFilter.java @@ -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; 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 { return parameterValues; } if (parameterValues == null || getQueryString() == null) { - return formParam.toArray(new String[formParam.size()]); + return StringUtils.toStringArray(formParam); } else { List 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); } } } diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index 19451d50198..08953acf63d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java @@ -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 { 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 { UriComponents uric = result.build(); String path = uric.getPath(); List 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("/"); } diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index d34f9b51ad6..e96cab4ab0d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java @@ -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 diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java index a854fe9f432..9554bdf5c7f 100644 --- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java +++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java @@ -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; 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 { @Override public String[] getValueNames() { assertIsValid(); - return this.attributes.keySet().toArray(new String[this.attributes.size()]); + return StringUtils.toStringArray(this.attributes.keySet()); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java index 84fcc4a92fd..03094a56347 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java @@ -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)); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java index 643b8ab0c7c..27248e9c399 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java @@ -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; 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 if (locations.isEmpty()) { locations.add("/WEB-INF/"); } - builder.addPropertyValue("templateLoaderPaths", locations.toArray(new String[locations.size()])); + builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations)); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java index b195a6df946..bdfc1cdb3cd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ScriptTemplateConfigurerBeanDefinitionParser.java @@ -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; 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 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")) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java index cfdd51ae950..6e1bf3c2cd2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/TilesConfigurerBeanDefinitionParser.java @@ -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; 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 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")); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java index 1d8dfaf288a..3b037f2d119 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java @@ -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 { /** - * 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 { 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 { 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; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java index f51ec904447..ef117d33fb7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java @@ -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; * Also provides matching logic to test if the interceptor applies to a given request path. * *

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 { /** * 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 { /** * 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 { /** * 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 { /** * 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 { /** - * 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. + *

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 { } /** - * 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 { /** - * 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 { 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 diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java index fc8c70c9d89..0e48ec97411 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java @@ -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)); } /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java index 603a3d82321..3c2b0e4ed66 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/AbstractWebSocketHandlerRegistration.java @@ -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; 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 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 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; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java index ec87c3044ea..edb80030944 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java @@ -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; 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 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; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java index 5c0583c6f90..ded13826fc7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/support/AbstractHandshakeHandler.java @@ -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 * 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 * @return the user for the WebSocket session, or {@code null} if not available */ @Nullable - protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, - Map attributes) { + protected Principal determineUser( + ServerHttpRequest request, WebSocketHandler wsHandler, Map attributes) { return request.getPrincipal(); }