diff --git a/build.gradle b/build.gradle index d1823485da..99134750c1 100644 --- a/build.gradle +++ b/build.gradle @@ -117,7 +117,7 @@ configure(allprojects) { project -> dependency "net.sf.ehcache:ehcache:2.10.6" dependency "org.ehcache:jcache:1.0.1" dependency "org.ehcache:ehcache:3.4.0" - dependency "org.hibernate:hibernate-core:5.4.19.Final" + dependency "org.hibernate:hibernate-core:5.4.20.Final" dependency "org.hibernate:hibernate-validator:6.1.5.Final" dependency "org.webjars:webjars-locator-core:0.45" dependency "org.webjars:underscorejs:1.8.3" diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index 45da25fa84..4fbfb43587 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -164,10 +164,10 @@ public class ConstructorArgumentValues { Assert.isTrue(index >= 0, "Index must not be negative"); ValueHolder valueHolder = this.indexedArgumentValues.get(index); if (valueHolder != null && - (valueHolder.getType() == null || - (requiredType != null && ClassUtils.matchesTypeName(requiredType, valueHolder.getType()))) && - (valueHolder.getName() == null || "".equals(requiredName) || - (requiredName != null && requiredName.equals(valueHolder.getName())))) { + (valueHolder.getType() == null || (requiredType != null && + ClassUtils.matchesTypeName(requiredType, valueHolder.getType()))) && + (valueHolder.getName() == null || (requiredName != null && + (requiredName.isEmpty() || requiredName.equals(valueHolder.getName()))))) { return valueHolder; } return null; @@ -277,17 +277,19 @@ public class ConstructorArgumentValues { * @return the ValueHolder for the argument, or {@code null} if none found */ @Nullable - public ValueHolder getGenericArgumentValue(@Nullable Class requiredType, @Nullable String requiredName, @Nullable Set usedValueHolders) { + public ValueHolder getGenericArgumentValue(@Nullable Class requiredType, @Nullable String requiredName, + @Nullable Set usedValueHolders) { + for (ValueHolder valueHolder : this.genericArgumentValues) { if (usedValueHolders != null && usedValueHolders.contains(valueHolder)) { continue; } - if (valueHolder.getName() != null && !"".equals(requiredName) && - (requiredName == null || !valueHolder.getName().equals(requiredName))) { + if (valueHolder.getName() != null && (requiredName == null || + (!requiredName.isEmpty() && !requiredName.equals(valueHolder.getName())))) { continue; } - if (valueHolder.getType() != null && - (requiredType == null || !ClassUtils.matchesTypeName(requiredType, valueHolder.getType()))) { + if (valueHolder.getType() != null && (requiredType == null || + !ClassUtils.matchesTypeName(requiredType, valueHolder.getType()))) { continue; } if (requiredType != null && valueHolder.getType() == null && valueHolder.getName() == null && diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java index b2f439b1fe..617a13be56 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java @@ -449,8 +449,8 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader else if (SINGLETON_KEY.equals(property)) { // Spring 1.2 style String val = StringUtils.trimWhitespace((String) entry.getValue()); - scope = ("".equals(val) || TRUE_VALUE.equals(val) ? BeanDefinition.SCOPE_SINGLETON : - BeanDefinition.SCOPE_PROTOTYPE); + scope = (!StringUtils.hasLength(val) || TRUE_VALUE.equals(val) ? + BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE); } else if (LAZY_INIT_KEY.equals(property)) { String val = StringUtils.trimWhitespace((String) entry.getValue()); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index 90d728303f..6be311eb1e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -1523,7 +1523,7 @@ public class BeanDefinitionParserDelegate { * Determine whether the given URI indicates the default namespace. */ public boolean isDefaultNamespace(@Nullable String namespaceUri) { - return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri)); + return !StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri); } /** @@ -1534,7 +1534,7 @@ public class BeanDefinitionParserDelegate { } private boolean isDefaultValue(String value) { - return (DEFAULT_VALUE.equals(value) || "".equals(value)); + return !StringUtils.hasLength(value) || DEFAULT_VALUE.equals(value); } private boolean isCandidateElement(Node node) { diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java index da969bf98a..37ffa85e40 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractResourceBasedMessageSource.java @@ -218,7 +218,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage * a non-classpath location. */ public void setCacheSeconds(int cacheSeconds) { - this.cacheMillis = (cacheSeconds * 1000); + this.cacheMillis = cacheSeconds * 1000L; } /** diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java index 338a23e691..2aaab8c4c5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java @@ -146,7 +146,7 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac * @see java.util.concurrent.ExecutorService#awaitTermination */ public void setAwaitTerminationSeconds(int awaitTerminationSeconds) { - this.awaitTerminationMillis = awaitTerminationSeconds * 1000; + this.awaitTerminationMillis = awaitTerminationSeconds * 1000L; } /** diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java index 0c47a413a9..eb8b310468 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi public void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { - if ("".equals(getNestedPath()) && !StringUtils.hasLength(field)) { + if (!StringUtils.hasLength(getNestedPath()) && !StringUtils.hasLength(field)) { // We're at the top of the nested object hierarchy, // so the present level is not a field but rather the top object. // The best we can do is register a global error here... diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java index fc5b0e22e4..5439bfa558 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -311,7 +311,7 @@ public class SpringValidatorAdapter implements SmartValidator, javax.validation. @Nullable protected Object getRejectedValue(String field, ConstraintViolation violation, BindingResult bindingResult) { Object invalidValue = violation.getInvalidValue(); - if (!"".equals(field) && !field.contains("[]") && + if (!field.isEmpty() && !field.contains("[]") && (invalidValue == violation.getLeafBean() || field.contains("[") || field.contains("."))) { // Possibly a bean constraint with property path: retrieve the actual property value. // However, explicitly avoid this for "address[]" style paths that we can't handle. diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java index 7eeaea2f24..92b0e3fc4b 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -126,7 +126,7 @@ public class SimpleNamingContext implements Context { if (logger.isDebugEnabled()) { logger.debug("Static JNDI lookup: [" + name + "]"); } - if ("".equals(name)) { + if (name.isEmpty()) { return new SimpleNamingContext(this.root, this.boundObjects, this.environment); } Object found = this.boundObjects.get(name); @@ -303,10 +303,10 @@ public class SimpleNamingContext implements Context { private abstract static class AbstractNamingEnumeration implements NamingEnumeration { - private Iterator iterator; + private final Iterator iterator; private AbstractNamingEnumeration(SimpleNamingContext context, String proot) throws NamingException { - if (!"".equals(proot) && !proot.endsWith("/")) { + if (!proot.isEmpty() && !proot.endsWith("/")) { proot = proot + "/"; } String root = context.root + proot; diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 9feda4082f..39d79fb2af 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -340,7 +340,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol URL url = resourceUrls.nextElement(); result.add(convertClassLoaderURL(url)); } - if ("".equals(path)) { + if (!StringUtils.hasLength(path)) { // The above result is likely to be incomplete, i.e. only containing file system references. // We need to have pointers to each of the jar files on the classpath as well... addAllClassLoaderJarRoots(cl, result); @@ -639,7 +639,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol if (logger.isTraceEnabled()) { logger.trace("Looking for matching resources in jar file [" + jarFileUrl + "]"); } - if (!"".equals(rootEntryPath) && !rootEntryPath.endsWith("/")) { + if (StringUtils.hasLength(rootEntryPath) && !rootEntryPath.endsWith("/")) { // Root entry path must end with slash to allow for proper matching. // The Sun JRE does not return a slash here, but BEA JRockit does. rootEntryPath = rootEntryPath + "/"; diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 7cf12a6925..123c71d5e2 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -331,6 +331,16 @@ public abstract class StringUtils { return sb.toString(); } + /** + * Test if the given {@code String} matches the given single character. + * @param str the {@code String} to check + * @param singleCharacter the character to compare to + * @since 5.2.9 + */ + public static boolean matchesCharacter(@Nullable String str, char singleCharacter) { + return (str != null && str.length() == 1 && str.charAt(0) == singleCharacter); + } + /** * Test if the given {@code String} starts with the specified prefix, * ignoring upper/lower case. @@ -716,7 +726,7 @@ public abstract class StringUtils { pathElements.add(0, TOP_PATH); } // If nothing else left, at least explicitly point to current path. - if (pathElements.size() == 1 && "".equals(pathElements.getLast()) && !prefix.endsWith(FOLDER_SEPARATOR)) { + if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) { pathElements.add(0, CURRENT_PATH); } diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java index 86d4fec4f6..a8e66fd602 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractListenerContainerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -255,7 +255,7 @@ abstract class AbstractListenerContainerParser implements BeanDefinitionParser { else if (DESTINATION_TYPE_TOPIC.equals(destinationType)) { pubSubDomain = true; } - else if ("".equals(destinationType) || DESTINATION_TYPE_QUEUE.equals(destinationType)) { + else if (!StringUtils.hasLength(destinationType) || DESTINATION_TYPE_QUEUE.equals(destinationType)) { // the default: queue } else { diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java index d00bb4b64d..0738ecfae1 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -64,10 +64,10 @@ class JmsListenerContainerParser extends AbstractListenerContainerParser { String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE); String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE); - if (!"".equals(containerClass)) { - return null; // Not supported + if (StringUtils.hasLength(containerClass)) { + return null; // not supported } - else if ("".equals(containerType) || containerType.startsWith("default")) { + else if (!StringUtils.hasLength(containerType) || containerType.startsWith("default")) { factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory"); } else if (containerType.startsWith("simple")) { @@ -91,10 +91,10 @@ class JmsListenerContainerParser extends AbstractListenerContainerParser { String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE); String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE); - if (!"".equals(containerClass)) { + if (StringUtils.hasLength(containerClass)) { containerDef.setBeanClassName(containerClass); } - else if ("".equals(containerType) || containerType.startsWith("default")) { + else if (!StringUtils.hasLength(containerType) || containerType.startsWith("default")) { containerDef.setBeanClassName("org.springframework.jms.listener.DefaultMessageListenerContainer"); } else if (containerType.startsWith("simple")) { diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java index f52b8191d4..14c4881c80 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -303,7 +303,7 @@ public class SimpleNamingContext implements Context { private abstract static class AbstractNamingEnumeration implements NamingEnumeration { - private Iterator iterator; + private final Iterator iterator; private AbstractNamingEnumeration(SimpleNamingContext context, String proot) throws NamingException { if (!proot.isEmpty() && !proot.endsWith("/")) { diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java index 38ea929213..72a1cab574 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -235,7 +235,7 @@ class MergedSqlConfig { private static String getString(AnnotationAttributes attributes, String attributeName, String defaultValue) { String value = attributes.getString(attributeName); - if ("".equals(value)) { + if (value.isEmpty()) { value = defaultValue; } return value; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index b2ea37b9fe..8b31ed1873 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -64,9 +64,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}. - * *

Implementation details: - * *

    *
  • Calls {@link #validateMergedContextConfiguration(MergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.
  • @@ -98,7 +96,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *
  • {@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.
  • *
- * * @return a new application context * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see GenericApplicationContext @@ -108,17 +105,17 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for merged context configuration [%s].", - mergedConfig)); + mergedConfig)); } validateMergedContextConfiguration(mergedConfig); GenericApplicationContext context = createContext(); - ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { context.setParent(parent); } + prepareContext(context); prepareContext(context, mergedConfig); customizeBeanFactory(context.getDefaultListableBeanFactory()); @@ -126,8 +123,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); customizeContext(context, mergedConfig); + context.refresh(); context.registerShutdownHook(); + return context; } @@ -147,9 +146,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load a Spring ApplicationContext from the supplied {@code locations}. - * *

Implementation details: - * *

    *
  • Calls {@link #createContext()} to create a {@link GenericApplicationContext} * instance.
  • @@ -168,12 +165,10 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader *
  • {@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.
  • *
- * *

Note: this method does not provide a means to set active bean definition * profiles for the loaded context. See {@link #loadContext(MergedContextConfiguration)} * and {@link AbstractContextLoader#prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)} * for an alternative. - * * @return a new application context * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericApplicationContext @@ -184,28 +179,30 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for locations [%s].", - StringUtils.arrayToCommaDelimitedString(locations))); + StringUtils.arrayToCommaDelimitedString(locations))); } + GenericApplicationContext context = createContext(); + prepareContext(context); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); + context.refresh(); context.registerShutdownHook(); + return context; } /** * Factory method for creating the {@link GenericApplicationContext} used by * this {@code ContextLoader}. - * *

The default implementation creates a {@code GenericApplicationContext} * using the default constructor. This method may be overridden in subclasses * — for example, to create a {@code GenericApplicationContext} with * a custom {@link DefaultListableBeanFactory} implementation. - * * @return a newly instantiated {@code GenericApplicationContext} * @since 5.2.9 */ @@ -216,10 +213,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}. * Called before bean definitions are read. - * *

The default implementation is empty. Can be overridden in subclasses to * customize {@code GenericApplicationContext}'s standard settings. - * * @param context the context that should be prepared * @since 2.5 * @see #loadContext(MergedContextConfiguration) @@ -235,10 +230,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Customize the internal bean factory of the ApplicationContext created by * this {@code ContextLoader}. - * *

The default implementation is empty but can be overridden in subclasses * to customize {@code DefaultListableBeanFactory}'s standard settings. - * * @param beanFactory the bean factory created by this {@code ContextLoader} * @since 2.5 * @see #loadContext(MergedContextConfiguration) @@ -254,18 +247,15 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Load bean definitions into the supplied {@link GenericApplicationContext context} * from the locations or classes in the supplied {@code MergedContextConfiguration}. - * *

The default implementation delegates to the {@link BeanDefinitionReader} * returned by {@link #createBeanDefinitionReader(GenericApplicationContext)} to * {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the * bean definitions. - * *

Subclasses must provide an appropriate implementation of * {@link #createBeanDefinitionReader(GenericApplicationContext)}. Alternatively subclasses * may provide a no-op implementation of {@code createBeanDefinitionReader()} * and override this method to provide a custom strategy for loading or * registering bean definitions. - * * @param context the context into which the bean definitions should be loaded * @param mergedConfig the merged context configuration * @since 3.1 @@ -278,7 +268,6 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Factory method for creating a new {@link BeanDefinitionReader} for loading * bean definitions into the supplied {@link GenericApplicationContext context}. - * * @param context the context for which the {@code BeanDefinitionReader} * should be created * @return a {@code BeanDefinitionReader} for the supplied context @@ -293,10 +282,8 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader * Customize the {@link GenericApplicationContext} created by this * {@code ContextLoader} after bean definitions have been * loaded into the context but before the context is refreshed. - * *

The default implementation is empty but can be overridden in subclasses * to customize the application context. - * * @param context the newly created application context * @since 2.5 * @see #loadContext(MergedContextConfiguration) diff --git a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java index f1352d006d..0ad453024d 100644 --- a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java +++ b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java @@ -49,7 +49,7 @@ class DefaultRequestPath implements RequestPath { } private static PathContainer initContextPath(PathContainer path, @Nullable String contextPath) { - if (!StringUtils.hasText(contextPath) || "/".equals(contextPath)) { + if (!StringUtils.hasText(contextPath) || StringUtils.matchesCharacter(contextPath, '/')) { return PathContainer.parsePath(""); } @@ -58,7 +58,7 @@ class DefaultRequestPath implements RequestPath { int length = contextPath.length(); int counter = 0; - for (int i=0; i < path.elements().size(); i++) { + for (int i = 0; i < path.elements().size(); i++) { PathContainer.Element element = path.elements().get(i); counter += element.value().length(); if (length == counter) { diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index d0ee04bc72..83226aa124 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -233,7 +233,7 @@ public class UrlPathHelper { } // Else, use path within current servlet mapping if applicable String rest = getPathWithinServletMapping(request); - if (!"".equals(rest)) { + if (StringUtils.hasLength(rest)) { return rest; } else { @@ -415,7 +415,7 @@ public class UrlPathHelper { if (contextPath == null) { contextPath = request.getContextPath(); } - if ("/".equals(contextPath)) { + if (StringUtils.matchesCharacter(contextPath, '/')) { // Invalid case, but happens for includes on Jetty: silently adapt it. contextPath = ""; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java index 52a4f33256..dcfb74e569 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ToStringVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -76,7 +76,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } private void indent() { - for (int i=0; i < this.indent; i++) { + for (int i = 0; i < this.indent; i++) { this.builder.append(' '); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java index 5e5fb3d3fe..31e8c4ed3e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ToStringVisitor.java @@ -38,6 +38,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi // RouterFunctions.Visitor + @Override public void startNested(RequestPredicate predicate) { indent(); @@ -74,11 +75,12 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } private void indent() { - for (int i=0; i < this.indent; i++) { + for (int i = 0; i < this.indent; i++) { this.builder.append(' '); } } + // RequestPredicates.Visitor @Override @@ -156,6 +158,7 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi public void unknown(RequestPredicate predicate) { this.builder.append(predicate); } + @Override public String toString() { String result = this.builder.toString(); @@ -164,4 +167,5 @@ class ToStringVisitor implements RouterFunctions.Visitor, RequestPredicates.Visi } return result; } + } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java index c0c1b6030c..097415af95 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java @@ -34,6 +34,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; @@ -145,7 +146,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i // We need to care for the default handler directly, since we need to // expose the PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE for it as well. Object rawHandler = null; - if ("/".equals(lookupPath)) { + if (StringUtils.matchesCharacter(lookupPath, '/')) { rawHandler = getRootHandler(); } if (rawHandler == null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index 8e0bde0c7a..c193ad5794 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; +import org.springframework.util.StringUtils; import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.util.UrlPathHelper; @@ -102,7 +103,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { throw new LookupPathIndexException(lookupPath, requestUri); } this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); - if ("/".equals(lookupPath) && !"/".equals(requestUri)) { + if (StringUtils.matchesCharacter(lookupPath, '/') && !StringUtils.matchesCharacter(requestUri, '/')) { String contextPath = pathHelper.getContextPath(this); if (requestUri.equals(contextPath)) { this.indexLookupPath = requestUri.length(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java index 9a7876ffcb..106f359f98 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ErrorsTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -260,7 +260,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { @Override protected String autogenerateId() throws JspException { String path = getPropertyPath(); - if ("".equals(path) || "*".equals(path)) { + if (!StringUtils.hasLength(path) || "*".equals(path)) { path = (String) this.pageContext.getAttribute( FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE); }