diff --git a/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentBeanDefinitionParser.java b/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentBeanDefinitionParser.java index de94cd90a01e..bd7b777cb383 100644 --- a/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentBeanDefinitionParser.java +++ b/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentBeanDefinitionParser.java @@ -39,7 +39,7 @@ private static AbstractBeanDefinition parseComponentElement(Element element) { factory.addPropertyValue("parent", parseComponent(element)); List childElements = DomUtils.getChildElementsByTagName(element, "component"); - if (!CollectionUtils.isEmpty(childElements)) { + if (CollectionUtils.isNotEmpty(childElements)) { parseChildComponents(childElements, factory); } diff --git a/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentFactoryBean.java b/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentFactoryBean.java index 7e5566ccc735..c27daa06e9c0 100644 --- a/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentFactoryBean.java +++ b/integration-tests/src/test/java/org/springframework/beans/factory/xml/ComponentFactoryBean.java @@ -19,6 +19,7 @@ import java.util.List; import org.springframework.beans.factory.FactoryBean; +import org.springframework.util.CollectionUtils; public class ComponentFactoryBean implements FactoryBean { @@ -35,7 +36,7 @@ public void setChildren(List children) { @Override public Component getObject() { - if (this.children != null && this.children.size() > 0) { + if (this.children != null && CollectionUtils.isNotEmpty(this.children)) { for (Component child : children) { this.parent.addComponent(child); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index bb75e0f23bbc..037d48ba4192 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -571,7 +571,7 @@ else if (this.joinPointStaticPartArgumentIndex != -1) { numBound++; } - if (!CollectionUtils.isEmpty(this.argumentBindings)) { + if (CollectionUtils.isNotEmpty(this.argumentBindings)) { // binding from pointcut match if (jpMatch != null) { PointcutParameter[] parameterBindings = jpMatch.getParameterBindings(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index ba670ff33bd0..996d8f005b80 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -378,7 +378,7 @@ public void addAdvisors(Collection advisors) { if (isFrozen()) { throw new AopConfigException("Cannot add advisor: Configuration is frozen."); } - if (!CollectionUtils.isEmpty(advisors)) { + if (CollectionUtils.isNotEmpty(advisors)) { for (Advisor advisor : advisors) { if (advisor instanceof IntroductionAdvisor introductionAdvisor) { validateIntroductionAdvisor(introductionAdvisor); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index e63144f44681..12a3481ae395 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -186,11 +186,11 @@ public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, C RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition(); beanDefinition.resolveDestroyMethodIfNecessary(); LifecycleMetadata metadata = findLifecycleMetadata(beanDefinition, registeredBean.getBeanClass()); - if (!CollectionUtils.isEmpty(metadata.initMethods)) { + if (CollectionUtils.isNotEmpty(metadata.initMethods)) { String[] initMethodNames = safeMerge(beanDefinition.getInitMethodNames(), metadata.initMethods); beanDefinition.setInitMethodNames(initMethodNames); } - if (!CollectionUtils.isEmpty(metadata.destroyMethods)) { + if (CollectionUtils.isNotEmpty(metadata.destroyMethods)) { String[] destroyMethodNames = safeMerge(beanDefinition.getDestroyMethodNames(), metadata.destroyMethods); beanDefinition.setDestroyMethodNames(destroyMethodNames); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java index 90e3cb9b49e3..2788746e7773 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java @@ -103,7 +103,7 @@ AbstractBeanDefinition getBeanDefinition() { protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(this.clazz); - if (!CollectionUtils.isEmpty(this.constructorArgs)) { + if (CollectionUtils.isNotEmpty(this.constructorArgs)) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : this.constructorArgs) { cav.addGenericArgumentValue(constructorArg); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java index 420e3eb9a370..a5ecb9317b7a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java @@ -194,7 +194,7 @@ public void run() { @Override public void destroy() { - if (!CollectionUtils.isEmpty(this.beanPostProcessors)) { + if (CollectionUtils.isNotEmpty(this.beanPostProcessors)) { for (DestructionAwareBeanPostProcessor processor : this.beanPostProcessors) { processor.postProcessBeforeDestruction(this.bean, this.beanName); } @@ -448,7 +448,7 @@ public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefin * @param postProcessors the post-processor candidates */ public static boolean hasApplicableProcessors(Object bean, List postProcessors) { - if (!CollectionUtils.isEmpty(postProcessors)) { + if (CollectionUtils.isNotEmpty(postProcessors)) { for (DestructionAwareBeanPostProcessor processor : postProcessors) { if (processor.requiresDestruction(bean)) { return true; @@ -467,7 +467,7 @@ public static boolean hasApplicableProcessors(Object bean, List processors, Object bean) { List filteredPostProcessors = null; - if (!CollectionUtils.isEmpty(processors)) { + if (CollectionUtils.isNotEmpty(processors)) { filteredPostProcessors = new ArrayList<>(processors.size()); for (DestructionAwareBeanPostProcessor processor : processors) { if (processor.requiresDestruction(bean)) { diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java index 7f15359c50ac..1f881413d10f 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactory.java @@ -299,7 +299,7 @@ public Configuration createConfiguration() throws IOException, TemplateException config.setSettings(props); } - if (!CollectionUtils.isEmpty(this.freemarkerVariables)) { + if (CollectionUtils.isNotEmpty(this.freemarkerVariables)) { config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper())); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java index 166b7b7da8f6..201d075e4f4c 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java @@ -74,7 +74,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera @Override public boolean hasCacheOperations(Method method, @Nullable Class targetClass) { - return !CollectionUtils.isEmpty(getCacheOperations(method, targetClass, false)); + return CollectionUtils.isNotEmpty(getCacheOperations(method, targetClass, false)); } @Override diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index e72ced10c1ed..7affca652600 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -399,7 +399,7 @@ protected void clearMetadataCache() { CacheOperationSource cacheOperationSource = getCacheOperationSource(); if (cacheOperationSource != null) { Collection operations = cacheOperationSource.getCacheOperations(method, targetClass); - if (!CollectionUtils.isEmpty(operations)) { + if (CollectionUtils.isNotEmpty(operations)) { return execute(invoker, method, new CacheOperationContexts(operations, method, args, target, targetClass)); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java index e4710dfc01c6..7e8588763e81 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java @@ -62,7 +62,7 @@ default boolean isCandidateClass(Class targetClass) { * @see #getCacheOperations */ default boolean hasCacheOperations(Method method, @Nullable Class targetClass) { - return !CollectionUtils.isEmpty(getCacheOperations(method, targetClass)); + return CollectionUtils.isNotEmpty(getCacheOperations(method, targetClass)); } /** diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index 91812cc9e0e4..b280cb2c693c 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -341,7 +341,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) @Override public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { - boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors); + boolean hasPropertySourceDescriptors = CollectionUtils.isNotEmpty(this.propertySourceDescriptors); boolean hasImportRegistry = beanFactory.containsBean(IMPORT_REGISTRY_BEAN_NAME); boolean hasBeanRegistrars = !this.beanRegistrars.isEmpty(); if (hasPropertySourceDescriptors || hasImportRegistry || hasBeanRegistrars) { diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index cc846e3e5f3b..8437f132bb68 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -914,7 +914,7 @@ protected void registerListeners() { // Publish early application events now that we finally have a multicaster... Set earlyEventsToProcess = this.earlyApplicationEvents; this.earlyApplicationEvents = null; - if (!CollectionUtils.isEmpty(earlyEventsToProcess)) { + if (CollectionUtils.isNotEmpty(earlyEventsToProcess)) { for (ApplicationEvent earlyEvent : earlyEventsToProcess) { getApplicationEventMulticaster().multicastEvent(earlyEvent); } diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index f5760107f59e..343bec85723f 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -591,7 +591,7 @@ public void start() { for (LifecycleGroupMember member : this.members) { doStart(this.lifecycleBeans, member.name, this.autoStartupOnly, futures); } - if (concurrentStartup != null && !CollectionUtils.isEmpty(futures)) { + if (concurrentStartup != null && CollectionUtils.isNotEmpty(futures)) { try { CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) .get(concurrentStartup, TimeUnit.MILLISECONDS); diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index fbc1b285a5ff..0cfb2fec56a1 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -123,7 +123,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased * @since 6.1 */ public void setFileExtensions(List fileExtensions) { - Assert.isTrue(!CollectionUtils.isEmpty(fileExtensions), "At least one file extension is required"); + Assert.isTrue(CollectionUtils.isNotEmpty(fileExtensions), "At least one file extension is required"); for (String extension : fileExtensions) { if (!extension.startsWith(".")) { throw new IllegalArgumentException("File extension '" + extension + "' should start with '.'"); @@ -379,18 +379,18 @@ protected List calculateFilenamesForLocale(String basename, Locale local StringBuilder temp = new StringBuilder(basename); temp.append('_'); - if (language.length() > 0) { + if (StringUtils.hasLength(language)) { temp.append(language); result.add(0, temp.toString()); } temp.append('_'); - if (country.length() > 0) { + if (StringUtils.hasLength(country)) { temp.append(country); result.add(0, temp.toString()); } - if (variant.length() > 0 && (language.length() > 0 || country.length() > 0)) { + if (StringUtils.hasLength(variant) && (StringUtils.hasLength(language) || StringUtils.hasLength(country))) { temp.append('_').append(variant); result.add(0, temp.toString()); } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java index cddae3bffc4e..70d30035cc4f 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java @@ -95,7 +95,7 @@ public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBe // null means any registered server, but "" specifically means the platform server if (!"".equals(agentId)) { List servers = MBeanServerFactory.findMBeanServer(agentId); - if (!CollectionUtils.isEmpty(servers)) { + if (CollectionUtils.isNotEmpty(servers)) { // Check to see if an MBeanServer is registered. if (servers.size() > 1 && logger.isInfoEnabled()) { logger.info("Found more than one MBeanServer instance" + diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java index dcb8826f4507..72abcafed64b 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java @@ -395,11 +395,11 @@ public void addOneTimeTask(DelayedTask task) { * @since 3.2 */ public boolean hasTasks() { - return (!CollectionUtils.isEmpty(this.triggerTasks) || - !CollectionUtils.isEmpty(this.cronTasks) || - !CollectionUtils.isEmpty(this.fixedRateTasks) || - !CollectionUtils.isEmpty(this.fixedDelayTasks) || - !CollectionUtils.isEmpty(this.oneTimeTasks)); + return (CollectionUtils.isNotEmpty(this.triggerTasks) || + CollectionUtils.isNotEmpty(this.cronTasks) || + CollectionUtils.isNotEmpty(this.fixedRateTasks) || + CollectionUtils.isNotEmpty(this.fixedDelayTasks) || + CollectionUtils.isNotEmpty(this.oneTimeTasks)); } diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java index df2c9a95b99c..fda11ec97131 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java @@ -346,7 +346,7 @@ public List getParameterNames(Method method) { } private void closeMappingStreams(@Nullable List mappingStreams){ - if (!CollectionUtils.isEmpty(mappingStreams)) { + if (CollectionUtils.isNotEmpty(mappingStreams)) { for (InputStream stream : mappingStreams) { try { stream.close(); 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 8b3194a2758c..1219f47bda2b 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 @@ -326,7 +326,7 @@ private AbstractNamingEnumeration(SimpleNamingContext context, String proot) thr } } } - if (contents.size() == 0) { + if (contents.isEmpty()) { throw new NamingException("Invalid root: [" + context.root + proot + "]"); } this.iterator = contents.values().iterator(); diff --git a/spring-core/src/main/java/org/springframework/asm/TypePath.java b/spring-core/src/main/java/org/springframework/asm/TypePath.java index b7cf845e7a4d..07333452eb59 100644 --- a/spring-core/src/main/java/org/springframework/asm/TypePath.java +++ b/spring-core/src/main/java/org/springframework/asm/TypePath.java @@ -117,7 +117,7 @@ public int getStepArgument(final int index) { * @return the corresponding TypePath object, or {@literal null} if the path is empty. */ public static TypePath fromString(final String typePath) { - if (typePath == null || typePath.length() == 0) { + if (typePath == null || typePath.isEmpty()) { return null; } int typePathLength = typePath.length(); diff --git a/spring-core/src/main/java/org/springframework/cglib/proxy/CallbackHelper.java b/spring-core/src/main/java/org/springframework/cglib/proxy/CallbackHelper.java index 4f8b3726f07b..e1befdf45112 100644 --- a/spring-core/src/main/java/org/springframework/cglib/proxy/CallbackHelper.java +++ b/spring-core/src/main/java/org/springframework/cglib/proxy/CallbackHelper.java @@ -63,7 +63,7 @@ public CallbackHelper(Class superclass, Class[] interfaces) { abstract protected Object getCallback(Method method); public Callback[] getCallbacks() { - if (callbacks.size() == 0) { + if (callbacks.isEmpty()) { return new Callback[0]; } if (callbacks.get(0) instanceof Callback) { @@ -75,7 +75,7 @@ public Callback[] getCallbacks() { } public Class[] getCallbackTypes() { - if (callbacks.size() == 0) { + if (callbacks.isEmpty()) { return new Class[0]; } if (callbacks.get(0) instanceof Callback) { diff --git a/spring-core/src/main/java/org/springframework/cglib/proxy/Enhancer.java b/spring-core/src/main/java/org/springframework/cglib/proxy/Enhancer.java index 3acd2fd69fe9..3cc889ed671d 100644 --- a/spring-core/src/main/java/org/springframework/cglib/proxy/Enhancer.java +++ b/spring-core/src/main/java/org/springframework/cglib/proxy/Enhancer.java @@ -755,7 +755,7 @@ public void generateClass(ClassVisitor v) throws Exception { */ protected void filterConstructors(Class sc, List constructors) { CollectionUtils.filter(constructors, new VisibilityPredicate(sc, true)); - if (constructors.size() == 0) { + if (constructors.isEmpty()) { throw new IllegalArgumentException("No visible constructors in " + sc); } } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java b/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java index f2ee2398c1cc..234d9f30938f 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/LocalizedResourceHelper.java @@ -24,6 +24,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Helper class for loading a localized resource, @@ -100,20 +101,20 @@ public Resource findLocalizedResource(String name, String extension, @Nullable L String variant = locale.getVariant(); // Check for file with language, country and variant localization. - if (variant.length() > 0) { + if (StringUtils.hasLength(variant)) { String location = name + this.separator + lang + this.separator + country + this.separator + variant + extension; resource = this.resourceLoader.getResource(location); } // Check for file with language and country localization. - if ((resource == null || !resource.exists()) && country.length() > 0) { + if ((resource == null || !resource.exists()) && StringUtils.hasLength(country)) { String location = name + this.separator + lang + this.separator + country + extension; resource = this.resourceLoader.getResource(location); } // Check for document with language localization. - if ((resource == null || !resource.exists()) && lang.length() > 0) { + if ((resource == null || !resource.exists()) && StringUtils.hasLength(lang)) { String location = name + this.separator + lang + extension; resource = this.resourceLoader.getResource(location); } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java index 9b073381234c..3935c0ecd330 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java @@ -35,6 +35,7 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.PlaceholderResolutionException; import org.springframework.util.ReflectionUtils; @@ -80,7 +81,7 @@ public void processPropertySource(PropertySourceDescriptor descriptor) throws IO String name = descriptor.name(); String encoding = descriptor.encoding(); List locations = descriptor.locations(); - Assert.isTrue(locations.size() > 0, "At least one @PropertySource(value) location is required"); + Assert.isTrue(CollectionUtils.isNotEmpty(locations), "At least one @PropertySource(value) location is required"); boolean ignoreResourceNotFound = descriptor.ignoreResourceNotFound(); PropertySourceFactory factory = (descriptor.propertySourceFactory() != null ? instantiateClass(descriptor.propertySourceFactory()) : defaultPropertySourceFactory); diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index cd62997a4a1a..cc4a072116c3 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -348,7 +348,7 @@ private boolean isPotentialMatch(String path, String[] pattDirs) { pos += skipped; skipped = skipSegment(path, pos, pattDir); if (skipped < pattDir.length()) { - return (skipped > 0 || (pattDir.length() > 0 && isWildcardChar(pattDir.charAt(0)))); + return (skipped > 0 || (StringUtils.hasLength(pattDir) && isWildcardChar(pattDir.charAt(0)))); } pos += skipped; } diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index 4d803ef7cf97..e55d07fd3f25 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -753,7 +753,7 @@ public static String classNamesToString(@Nullable Collection> classes) * @see StringUtils#toStringArray */ public static Class[] toClassArray(@Nullable Collection> collection) { - return (!CollectionUtils.isEmpty(collection) ? collection.toArray(EMPTY_CLASS_ARRAY) : EMPTY_CLASS_ARRAY); + return (CollectionUtils.isNotEmpty(collection) ? collection.toArray(EMPTY_CLASS_ARRAY) : EMPTY_CLASS_ARRAY); } /** diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index 4a41a9c947ed..21ab89dfe79c 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -80,6 +80,27 @@ public static boolean isEmpty(@Nullable Map map) return (map == null || map.isEmpty()); } + /** + * Return {@code true} if the supplied Collection is not {@code null} and not empty. + * Otherwise, return {@code false}. + * @param collection the Collection to check + * @return whether the given Collection is not empty + */ + public static boolean isNotEmpty(@Nullable Collection collection) { + return (collection != null && !collection.isEmpty()); + } + + /** + * Return {@code true} if the supplied Map is not {@code null} and not empty. + * Otherwise, return {@code false}. + * @param map the Map to check + * @return whether the given Map is not empty + */ + public static boolean isNotEmpty(@Nullable Map map) { + return (map != null && !map.isEmpty()); + } + + /** * Instantiate a new {@link HashMap} with an initial capacity * that can accommodate the specified number of elements without diff --git a/spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java b/spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java index 7d6f4f3e5ccc..70f2902f5b1a 100644 --- a/spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java +++ b/spring-core/src/main/java/org/springframework/util/CommonsLogWriter.java @@ -44,7 +44,7 @@ public CommonsLogWriter(Log logger) { public void write(char ch) { - if (ch == '\n' && this.buffer.length() > 0) { + if (ch == '\n' && StringUtils.hasLength(this.buffer)) { logger.debug(this.buffer.toString()); this.buffer.setLength(0); } diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index 7e02f5528da2..f495a91c1e68 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -181,7 +181,7 @@ public MimeType(String type, String subtype, @Nullable Map param checkToken(subtype); this.type = type.toLowerCase(Locale.ROOT); this.subtype = subtype.toLowerCase(Locale.ROOT); - if (!CollectionUtils.isEmpty(parameters)) { + if (CollectionUtils.isNotEmpty(parameters)) { Map map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ROOT); parameters.forEach((parameter, value) -> { checkParameters(parameter, value); diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index 1b9b668ba0d3..7d1b9b6b614e 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -244,7 +244,7 @@ else if (ch == '"') { nextIndex++; } String parameter = mimeType.substring(index + 1, nextIndex).trim(); - if (parameter.length() > 0) { + if (StringUtils.hasLength(parameter)) { if (parameters == null) { parameters = new LinkedHashMap<>(4); } diff --git a/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java index a8156636de8d..56763f9a77b2 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java @@ -201,7 +201,7 @@ public void forEach(BiConsumer action) { } private @Nullable V adaptValue(@Nullable List values) { - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { return values.get(0); } else { diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java index 6db806ba6f0c..9ae7312f26d3 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java @@ -58,7 +58,7 @@ public MultiValueMapAdapter(Map> targetMap) { @Override public @Nullable V getFirst(K key) { List values = this.targetMap.get(key); - return (!CollectionUtils.isEmpty(values) ? values.get(0) : null); + return (CollectionUtils.isNotEmpty(values) ? values.get(0) : null); } @Override @@ -94,7 +94,7 @@ public void setAll(Map values) { public Map toSingleValueMap() { Map singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size()); this.targetMap.forEach((key, values) -> { - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { singleValueMap.put(key, values.get(0)); } }); diff --git a/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java b/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java index 338cf9233cea..f0c999982e8a 100644 --- a/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java +++ b/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java @@ -60,7 +60,7 @@ private PlaceholderResolutionException(String reason, String placeholder, List values) { StringBuilder sb = new StringBuilder(); sb.append(reason); - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { String valuesChain = values.stream().map(value -> "\"" + value + "\"") .collect(Collectors.joining(" <-- ")); sb.append(" in value %s".formatted(valuesChain)); 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 df2e0d8ccbfa..d0b09a659c2b 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -1001,7 +1001,7 @@ public static TimeZone parseTimeZoneString(String timeZoneString) { * @return the resulting {@code String} array */ public static String[] toStringArray(@Nullable Collection collection) { - return (!CollectionUtils.isEmpty(collection) ? collection.toArray(EMPTY_STRING_ARRAY) : EMPTY_STRING_ARRAY); + return (CollectionUtils.isNotEmpty(collection) ? collection.toArray(EMPTY_STRING_ARRAY) : EMPTY_STRING_ARRAY); } /** diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java index 981ef9145300..025ec5aadfe4 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java @@ -149,7 +149,7 @@ else if (ClassUtils.isAssignable(paramTypeClazz, superClass)) { static @Nullable ArgumentsMatchKind compareArgumentsVarargs( List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) { - Assert.isTrue(!CollectionUtils.isEmpty(expectedArgTypes), + Assert.isTrue(CollectionUtils.isNotEmpty(expectedArgTypes), "Expected arguments must at least include one array (the varargs parameter)"); Assert.isTrue(expectedArgTypes.get(expectedArgTypes.size() - 1).isArray(), "Final expected argument should be array type (the varargs parameter)"); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java index b5f051359ce2..328180096b7d 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java @@ -443,7 +443,7 @@ protected boolean isCandidateForProperty(Method method, Class targetClass) { */ protected String[] getPropertyMethodSuffixes(String propertyName) { String suffix = getPropertyMethodSuffix(propertyName); - if (suffix.length() > 0 && Character.isUpperCase(suffix.charAt(0))) { + if (StringUtils.hasLength(suffix) && Character.isUpperCase(suffix.charAt(0))) { return new String[] {suffix}; } return new String[] {suffix, StringUtils.capitalize(suffix)}; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index 1a082c6dd676..2b074eddff77 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -338,7 +338,7 @@ private static String readScript(LineNumberReader lineNumberReader, String @Null while (currentStatement != null) { if ((blockCommentEndDelimiter != null && currentStatement.contains(blockCommentEndDelimiter)) || (commentPrefixes != null && !startsWithAny(currentStatement, commentPrefixes, 0))) { - if (scriptBuilder.length() > 0) { + if (StringUtils.hasLength(scriptBuilder)) { scriptBuilder.append('\n'); } scriptBuilder.append(currentStatement); @@ -508,7 +508,7 @@ else if (!inSingleQuote && (c == '"')) { if (!inSingleQuote && !inDoubleQuote) { if (script.startsWith(separator, i)) { // We've reached the end of the current statement - if (sb.length() > 0) { + if (StringUtils.hasLength(sb)) { statements.add(sb.toString()); sb = new StringBuilder(); } @@ -541,7 +541,7 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) { } else if (c == ' ' || c == '\r' || c == '\n' || c == '\t') { // Avoid multiple adjacent whitespace characters - if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { + if (StringUtils.hasLength(sb) && sb.charAt(sb.length() - 1) != ' ') { c = ' '; } else { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java index 7b1d29bd7723..e3865fe90955 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java @@ -344,12 +344,12 @@ protected Mono handleMatch( CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message message) { Set patterns = mapping.getCondition(DestinationPatternsMessageCondition.class).getPatterns(); - if (!CollectionUtils.isEmpty(patterns)) { + if (CollectionUtils.isNotEmpty(patterns)) { String pattern = patterns.iterator().next(); RouteMatcher.Route destination = getDestination(message); Assert.state(destination != null, "Missing destination header"); Map vars = obtainRouteMatcher().matchAndExtract(pattern, destination); - if (!CollectionUtils.isEmpty(vars)) { + if (CollectionUtils.isNotEmpty(vars)) { MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); Assert.state(mha != null && mha.isMutable(), "Mutable MessageHeaderAccessor required"); mha.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java index a368b00eaa59..276dfd267aa3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java @@ -89,7 +89,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol public PayloadMethodArgumentResolver(List> decoders, @Nullable Validator validator, @Nullable ReactiveAdapterRegistry registry, boolean useDefaultResolution) { - Assert.isTrue(!CollectionUtils.isEmpty(decoders), "At least one Decoder is required"); + Assert.isTrue(CollectionUtils.isNotEmpty(decoders), "At least one Decoder is required"); this.decoders = List.copyOf(decoders); this.validator = validator; this.adapterRegistry = registry != null ? registry : ReactiveAdapterRegistry.getSharedInstance(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java index a50c1db08695..d672fd313706 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java @@ -266,7 +266,7 @@ private Mono getSetupPayload( MimeType dataMimeType, MimeType metaMimeType, RSocketStrategies strategies) { Object data = this.setupData; - boolean hasMetadata = (this.setupRoute != null || !CollectionUtils.isEmpty(this.setupMetadata)); + boolean hasMetadata = (this.setupRoute != null || CollectionUtils.isNotEmpty(this.setupMetadata)); if (!hasMetadata && data == null) { return Mono.just(EMPTY_SETUP_PAYLOAD); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java index 5c08bc5fc837..e981292b6743 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java @@ -158,7 +158,7 @@ public MetadataEncoder metadataAndOrRoute(@Nullable Map metada if (route != null) { this.route = expand(route, vars != null ? vars : new Object[0]); } - if (!CollectionUtils.isEmpty(metadata)) { + if (CollectionUtils.isNotEmpty(metadata)) { for (Map.Entry entry : metadata.entrySet()) { metadata(entry.getKey(), entry.getValue()); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java index 71b8e38219ad..4df14d82ca4f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java @@ -203,7 +203,7 @@ public String getShortLogMessage(Object payload) { return super.getDetailedLogMessage(payload); } StringBuilder sb = getBaseLogMessage(); - if (!CollectionUtils.isEmpty(getSessionAttributes())) { + if (CollectionUtils.isNotEmpty(getSessionAttributes())) { sb.append(" attributes[").append(getSessionAttributes().size()).append(']'); } sb.append(getShortPayloadLogMessage(payload)); @@ -217,10 +217,10 @@ public String getDetailedLogMessage(@Nullable Object payload) { return super.getDetailedLogMessage(payload); } StringBuilder sb = getBaseLogMessage(); - if (!CollectionUtils.isEmpty(getSessionAttributes())) { + if (CollectionUtils.isNotEmpty(getSessionAttributes())) { sb.append(" attributes=").append(getSessionAttributes()); } - if (!CollectionUtils.isEmpty((Map>) getHeader(NATIVE_HEADERS))) { + if (CollectionUtils.isNotEmpty((Map>) getHeader(NATIVE_HEADERS))) { sb.append(" nativeHeaders=").append(getHeader(NATIVE_HEADERS)); } sb.append(getDetailedPayloadLogMessage(payload)); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index 8aa4bd89281d..634afb91e567 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -503,10 +503,10 @@ protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handler String lookupDestination, Message message) { Set patterns = mapping.getDestinationConditions().getPatterns(); - if (!CollectionUtils.isEmpty(patterns)) { + if (CollectionUtils.isNotEmpty(patterns)) { String pattern = patterns.iterator().next(); Map vars = getPathMatcher().extractUriTemplateVariables(pattern, lookupDestination); - if (!CollectionUtils.isEmpty(vars)) { + if (CollectionUtils.isNotEmpty(vars)) { MessageHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); Assert.state(mha != null && mha.isMutable(), "Mutable MessageHeaderAccessor required"); mha.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index d54ea520059e..5dd83b925c26 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -33,6 +33,7 @@ import org.springframework.util.InvalidMimeTypeException; import org.springframework.util.MultiValueMap; import org.springframework.util.StreamUtils; +import org.springframework.util.StringUtils; /** * Decodes one or more STOMP frames contained in a {@link ByteBuffer}. @@ -134,7 +135,7 @@ public List> decode(ByteBuffer byteBuffer, byteBuffer.mark(); String command = readCommand(byteBuffer); - if (command.length() > 0) { + if (StringUtils.hasLength(command)) { StompHeaderAccessor headerAccessor = null; byte[] payload = null; if (byteBuffer.remaining() > 0) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java index 97839a678c62..7218babf6eed 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java @@ -528,7 +528,7 @@ public static StompHeaderAccessor wrap(Message message) { public static @Nullable Integer getContentLength(Map> nativeHeaders) { List values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); - return (!CollectionUtils.isEmpty(values) ? Integer.valueOf(values.get(0)) : null); + return (CollectionUtils.isNotEmpty(values) ? Integer.valueOf(values.get(0)) : null); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java index 5c0b4b1c6421..6787e399bf62 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java @@ -62,7 +62,7 @@ protected NativeMessageHeaderAccessor() { * @param nativeHeaders native headers to create the message with (may be {@code null}) */ protected NativeMessageHeaderAccessor(@Nullable Map> nativeHeaders) { - if (!CollectionUtils.isEmpty(nativeHeaders)) { + if (CollectionUtils.isNotEmpty(nativeHeaders)) { setHeader(NATIVE_HEADERS, new LinkedMultiValueMap<>(nativeHeaders)); } } @@ -172,7 +172,7 @@ public boolean containsNativeHeader(String headerName) { Map> map = getNativeHeaders(); if (map != null) { List values = map.get(headerName); - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { return values.get(0); } } @@ -292,7 +292,7 @@ public void addNativeHeaders(@Nullable MultiValueMap headers) { Map> map = (Map>) headers.get(NATIVE_HEADERS); if (map != null) { List values = map.get(headerName); - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { return values.get(0); } } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/AbstractStompBrokerRelayIntegrationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/AbstractStompBrokerRelayIntegrationTests.java index 985ce165b5cb..540c1b53af1d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/AbstractStompBrokerRelayIntegrationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/AbstractStompBrokerRelayIntegrationTests.java @@ -49,6 +49,7 @@ import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.tcp.TcpOperations; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -293,7 +294,7 @@ public void handleMessage(Message message) throws MessagingException { public void expectMessages(MessageExchange... messageExchanges) throws InterruptedException { List expectedMessages = new ArrayList<>(Arrays.asList(messageExchanges)); - while (expectedMessages.size() > 0) { + while (CollectionUtils.isNotEmpty(expectedMessages)) { Message message = this.queue.poll(10000, TimeUnit.MILLISECONDS); assertThat(message).as("Timed out waiting for messages, expected [" + expectedMessages + "]").isNotNull(); MessageExchange match = findMatch(expectedMessages, message); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index 05c6bccf726d..fe39d99bb2ea 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -362,7 +362,7 @@ public void afterPropertiesSet() throws PersistenceException { PersistenceUnitInfo pui = getPersistenceUnitInfo(); Map vendorPropertyMap = (pui != null ? jpaVendorAdapter.getJpaPropertyMap(pui) : jpaVendorAdapter.getJpaPropertyMap()); - if (!CollectionUtils.isEmpty(vendorPropertyMap)) { + if (CollectionUtils.isNotEmpty(vendorPropertyMap)) { vendorPropertyMap.forEach((key, value) -> { if (!this.jpaPropertyMap.containsKey(key)) { this.jpaPropertyMap.put(key, value); @@ -583,7 +583,7 @@ public EntityManagerFactory getNativeEntityManagerFactory() { @Override public EntityManager createNativeEntityManager(@Nullable Map properties) { - EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? + EntityManager rawEntityManager = (CollectionUtils.isNotEmpty(properties) ? getNativeEntityManagerFactory().createEntityManager(properties) : getNativeEntityManagerFactory().createEntityManager()); postProcessEntityManager(rawEntityManager); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java index 81c3c4972ae9..92eef4046129 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryAccessor.java @@ -162,7 +162,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException { protected EntityManager createEntityManager() throws IllegalStateException { EntityManagerFactory emf = obtainEntityManagerFactory(); Map properties = getJpaPropertyMap(); - return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); + return (CollectionUtils.isNotEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); } /** diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java index 6037f5e93ef9..452a3f1e2316 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java @@ -259,7 +259,7 @@ else if (!TransactionSynchronizationManager.isSynchronizationActive()) { } } if (em == null) { - em = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); + em = (CollectionUtils.isNotEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); } try { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java index 72b050dd902e..fd279d5762ec 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/ExtendedEntityManagerCreator.java @@ -174,7 +174,7 @@ public static EntityManager createContainerManagedEntityManager( return createProxy(rawEntityManager, emfInfo, true, synchronizedWithTransaction); } else { - EntityManager rawEntityManager = (!CollectionUtils.isEmpty(properties) ? + EntityManager rawEntityManager = (CollectionUtils.isNotEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); return createProxy(rawEntityManager, null, null, null, null, true, synchronizedWithTransaction); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java index a452992632c0..45997d7ee15c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java @@ -477,7 +477,7 @@ protected EntityManager createEntityManagerForTransaction() { em = emfInfo.createNativeEntityManager(properties); } else { - em = (!CollectionUtils.isEmpty(properties) ? + em = (CollectionUtils.isNotEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); } if (this.entityManagerInitializer != null) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 44cd372cb180..34e6dd2079b4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -376,7 +376,7 @@ public void afterPropertiesSet() throws PersistenceException { } List qualifiers = this.persistenceUnitInfo.getQualifierAnnotationNames(); - if (!CollectionUtils.isEmpty(qualifiers)) { + if (CollectionUtils.isNotEmpty(qualifiers)) { BeanFactory beanFactory = getBeanFactory(); String beanName = getBeanName(); if (beanFactory instanceof ConfigurableBeanFactory cbf && beanName != null) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java index e4d6030329fa..efe9e7ec9605 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java @@ -306,7 +306,7 @@ private void initProxyClassLoader() { boolean isNewEm = false; if (target == null) { logger.debug("Creating new EntityManager for shared EntityManager invocation"); - target = (!CollectionUtils.isEmpty(this.properties) ? + target = (CollectionUtils.isNotEmpty(this.properties) ? this.targetFactory.createEntityManager(this.properties) : this.targetFactory.createEntityManager()); isNewEm = true; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index 8fa6c50b30c7..bb412e7ce48d 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -361,7 +361,7 @@ public void resetBeanDefinition(String beanName) { InjectionMetadata metadata = findInjectionMetadata(beanDefinition, beanClass, beanName); Collection injectedElements = metadata.getInjectedElements( beanDefinition.getPropertyValues()); - if (!CollectionUtils.isEmpty(injectedElements)) { + if (CollectionUtils.isNotEmpty(injectedElements)) { return new AotContribution(beanClass, injectedElements); } return null; @@ -863,7 +863,7 @@ private void generateGetEntityManagerMethod(MethodSpec.Builder method, Persisten "$T entityManagerFactory = $T.findEntityManagerFactory(($T) $L.getBeanFactory(), $S)", EntityManagerFactory.class, EntityManagerFactoryUtils.class, ListableBeanFactory.class, REGISTERED_BEAN_PARAMETER, unitName); - boolean hasProperties = !CollectionUtils.isEmpty(properties); + boolean hasProperties = CollectionUtils.isNotEmpty(properties); if (hasProperties) { method.addStatement("$T properties = new Properties()", Properties.class); diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java index c927ff0bee62..4a68ca9c35f0 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java @@ -487,7 +487,7 @@ else if (!inSingleQuote && (c == '"')) { if (!inSingleQuote && !inDoubleQuote) { if (script.startsWith(separator, i)) { // We've reached the end of the current statement - if (sb.length() > 0) { + if (StringUtils.hasLength(sb)) { statements.add(sb.toString()); sb = new StringBuilder(); } @@ -520,7 +520,7 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) { } else if (c == ' ' || c == '\r' || c == '\n' || c == '\t') { // Avoid multiple adjacent whitespace characters - if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { + if (StringUtils.hasLength(sb) && sb.charAt(sb.length() - 1) != ' ') { c = ' '; } else { diff --git a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java index 91915ea3e709..428fd48f63ba 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java @@ -69,7 +69,7 @@ public XpathExpectationsHelper(String expression, @Nullable Map this.expression = String.format(expression, args); this.xpathExpression = compileXpathExpression(this.expression, namespaces); - this.hasNamespaces = !CollectionUtils.isEmpty(namespaces); + this.hasNamespaces = CollectionUtils.isNotEmpty(namespaces); } private static XPathExpression compileXpathExpression(String expression, 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 e8c3fbf1f35d..a22011266229 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 @@ -23,6 +23,7 @@ import java.util.Set; import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; import org.springframework.web.servlet.ModelAndView; import static org.springframework.test.util.AssertionErrors.assertTrue; @@ -128,7 +129,7 @@ public static void assertModelAttributeValues(ModelAndView mav, Map T self() { @Override public WebTestClient.Builder configureClient() { WebHttpHandlerBuilder builder = initHttpHandlerBuilder(); - if (!CollectionUtils.isEmpty(this.filters)) { + if (CollectionUtils.isNotEmpty(this.filters)) { builder.filters(theFilters -> theFilters.addAll(0, this.filters)); } if (!builder.hasSessionManager() && this.sessionManager != null) { builder.sessionManager(this.sessionManager); } - if (!CollectionUtils.isEmpty(this.configurers)) { + if (CollectionUtils.isNotEmpty(this.configurers)) { this.configurers.forEach(configurer -> configurer.beforeServerCreated(builder)); } return new DefaultWebTestClientBuilder(builder, this.sslInfo); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index e033410cd706..bdde3380d115 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -397,10 +397,10 @@ private ClientRequest.Builder initRequestBuilder() { } }) .cookies(cookiesToUse -> { - if (!CollectionUtils.isEmpty(DefaultWebTestClient.this.defaultCookies)) { + if (CollectionUtils.isNotEmpty(DefaultWebTestClient.this.defaultCookies)) { cookiesToUse.putAll(DefaultWebTestClient.this.defaultCookies); } - if (!CollectionUtils.isEmpty(this.cookies)) { + if (CollectionUtils.isNotEmpty(this.cookies)) { cookiesToUse.putAll(this.cookies); } }) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java index ce008c059d3f..0f390c44a031 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java @@ -199,7 +199,7 @@ private String getRequiredValue(String name) { private List getRequiredValues(String name) { List values = getHeaders().get(name); - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { return values; } else { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java index e5a9de0f555a..71a91245c23d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java @@ -272,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar public String processMultipartFileList(@RequestParam(required = false) List file, @RequestPart(required = false) Map json) throws IOException { - if (!CollectionUtils.isEmpty(file)) { + if (CollectionUtils.isNotEmpty(file)) { byte[] content = file.get(0).getBytes(); assertThat(file.get(1).getBytes()).isEqualTo(content); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java index 43fe353e7780..b7f5e44351b2 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java @@ -272,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar public String processMultipartFileList(@RequestParam(required = false) List file, @RequestPart(required = false) Map json) throws IOException { - if (!CollectionUtils.isEmpty(file)) { + if (CollectionUtils.isNotEmpty(file)) { byte[] content = file.get(0).getBytes(); assertThat(file.get(1).getBytes()).isEqualTo(content); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java index 61f857f1d621..dadb59d4979d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java @@ -142,7 +142,7 @@ protected void applyCookies() { if (getCookies().isEmpty()) { return; } - if (!CollectionUtils.isEmpty(getCookies())) { + if (CollectionUtils.isNotEmpty(getCookies())) { this.httpRequest.setHeader(HttpHeaders.COOKIE, serializeCookies()); } } diff --git a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java index a4436fb391eb..43d8f0f1a8cc 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java @@ -96,7 +96,7 @@ public void setRequestFactory(ClientHttpRequestFactory requestFactory) { @Override public ClientHttpRequestFactory getRequestFactory() { List interceptors = getInterceptors(); - if (!CollectionUtils.isEmpty(interceptors)) { + if (CollectionUtils.isNotEmpty(interceptors)) { ClientHttpRequestFactory factory = this.interceptingRequestFactory; if (factory == null) { factory = new InterceptingClientHttpRequestFactory( diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java index 3514e2c82aee..79bc52f24aee 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java @@ -26,6 +26,7 @@ import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; +import org.springframework.util.StringUtils; import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; @@ -162,7 +163,7 @@ protected String serializeForm(MultiValueMap formData, Charset c StringBuilder builder = new StringBuilder(); formData.forEach((name, values) -> values.forEach(value -> { - if (builder.length() != 0) { + if (StringUtils.hasLength(builder)) { builder.append('&'); } builder.append(URLEncoder.encode(name, charset)); diff --git a/spring-web/src/main/java/org/springframework/http/codec/JacksonCodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/JacksonCodecSupport.java index ac52c2ca29ca..6c27dbd8c840 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/JacksonCodecSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/JacksonCodecSupport.java @@ -189,7 +189,7 @@ protected List getMimeTypes(ResolvableType elementType) { result.addAll(entry.getValue().keySet()); } } - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return result; } return (ProblemDetail.class.isAssignableFrom(elementClass) ? getMediaTypesForProblemDetail() : getMimeTypes()); diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java index caf6ce985f93..0f5b72ff6b12 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java @@ -181,7 +181,7 @@ protected List getMimeTypes(ResolvableType elementType) { result.addAll(entry.getValue().keySet()); } } - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return result; } return (ProblemDetail.class.isAssignableFrom(elementClass) ? getMediaTypesForProblemDetail() : getMimeTypes()); diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractJacksonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractJacksonHttpMessageConverter.java index da328cbee4d3..9f915776f7cd 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractJacksonHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractJacksonHttpMessageConverter.java @@ -238,7 +238,7 @@ public List getSupportedMediaTypes(Class clazz) { result.addAll(entry.getValue().keySet()); } } - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return result; } return (ProblemDetail.class.isAssignableFrom(clazz) ? diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 18839993f368..995a5ebfb2d4 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -444,7 +444,7 @@ protected String serializeForm(MultiValueMap formData, Charset c return; } values.forEach(value -> { - if (builder.length() != 0) { + if (StringUtils.hasLength(builder)) { builder.append('&'); } builder.append(URLEncoder.encode(name, charset)); diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java index 2af26f543184..ac2ef3241ba7 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java @@ -203,7 +203,7 @@ public List getSupportedMediaTypes(Class clazz) { result.addAll(entry.getValue().keySet()); } } - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return result; } return (ProblemDetail.class.isAssignableFrom(clazz) ? diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index 08433f995781..eb50081f129a 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -158,7 +158,7 @@ public void setParameterName(String parameterName) { * @see #addMediaTypes(Map) */ public void setMediaTypes(Properties mediaTypes) { - if (!CollectionUtils.isEmpty(mediaTypes)) { + if (CollectionUtils.isNotEmpty(mediaTypes)) { mediaTypes.forEach((key, value) -> addMediaType((String) key, MediaType.valueOf((String) value))); } @@ -269,7 +269,7 @@ public ContentNegotiationManager build() { // Ensure media type mappings are available via ContentNegotiationManager#getMediaTypeMappings() // independent of path extension or parameter strategies. - if (!CollectionUtils.isEmpty(this.mediaTypes) && !this.favorParameter) { + if (CollectionUtils.isNotEmpty(this.mediaTypes) && !this.favorParameter) { this.contentNegotiationManager.addFileExtensionResolvers( new MappingMediaTypeFileExtensionResolver(this.mediaTypes)); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java index 14050d9f4179..f2eca7535a99 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/HeaderContentNegotiationStrategy.java @@ -54,7 +54,7 @@ public List resolveMediaTypes(NativeWebRequest request) try { List mediaTypes = MediaType.parseMediaTypes(headerValues); MimeTypeUtils.sortBySpecificity(mediaTypes); - return !CollectionUtils.isEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST; + return CollectionUtils.isNotEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST; } catch (InvalidMediaTypeException | InvalidMimeTypeException ex) { throw new HttpMediaTypeNotAcceptableException( diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java index 8f71b1053df7..e821791bf1d2 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java @@ -147,7 +147,7 @@ public static Mono> extractValuesToBind(ServerWebExchange ex } protected static void addBindValue(Map params, String key, List values) { - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { if (values.size() == 1) { params.put(key, adaptBindValue(values.get(0))); } diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java index 46768cba0301..cf7c04b225a6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultResponseErrorHandler.java @@ -151,7 +151,7 @@ else if (statusCode.is5xxServerError()) { ex = new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset); } - if (!CollectionUtils.isEmpty(this.messageConverters)) { + if (CollectionUtils.isNotEmpty(this.messageConverters)) { ex.setBodyConvertFunction(initBodyConvertFunction(response, body)); } @@ -226,7 +226,7 @@ private String getErrorMessage( */ @SuppressWarnings("NullAway") // Lambda protected Function initBodyConvertFunction(ClientHttpResponse response, byte[] body) { - Assert.state(!CollectionUtils.isEmpty(this.messageConverters), "Expected message converters"); + Assert.state(CollectionUtils.isNotEmpty(this.messageConverters), "Expected message converters"); return resolvableType -> { try { HttpMessageConverterExtractor extractor = diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index 5f7e04535eaa..56559500fba7 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -663,7 +663,7 @@ else if (CollectionUtils.isEmpty(defaultCookies)) { map.putAll(defaultCookies); map.putAll(this.cookies); } - return (!CollectionUtils.isEmpty(map) ? serializeCookies(map) : null); + return (CollectionUtils.isNotEmpty(map) ? serializeCookies(map) : null); } private static String serializeCookies(MultiValueMap map) { diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java index ae1904b26410..a5f22c6071d4 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java @@ -152,11 +152,11 @@ public DefaultRestClientBuilder(RestTemplate restTemplate) { this.uriBuilderFactory = getUriBuilderFactory(restTemplate); this.statusHandlers = new ArrayList<>(); this.statusHandlers.add(StatusHandler.fromErrorHandler(restTemplate.getErrorHandler())); - if (!CollectionUtils.isEmpty(restTemplate.getInterceptors())) { + if (CollectionUtils.isNotEmpty(restTemplate.getInterceptors())) { this.interceptors = new ArrayList<>(restTemplate.getInterceptors()); } this.bufferingPredicate = restTemplate.getBufferingPredicate(); - if (!CollectionUtils.isEmpty(restTemplate.getClientHttpRequestInitializers())) { + if (CollectionUtils.isNotEmpty(restTemplate.getClientHttpRequestInitializers())) { this.initializers = new ArrayList<>(restTemplate.getClientHttpRequestInitializers()); } this.requestFactory = getRequestFactory(restTemplate); diff --git a/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java index 0a3d69581f2f..d1e94a1f8c78 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java @@ -106,7 +106,7 @@ public void setMessageConverters(List> messageConverters * {@link RestClientException}. */ public void setStatusMapping(Map> statusMapping) { - if (!CollectionUtils.isEmpty(statusMapping)) { + if (CollectionUtils.isNotEmpty(statusMapping)) { this.statusMapping.putAll(statusMapping); } } @@ -122,7 +122,7 @@ public void setStatusMapping(Map> seriesMapping) { - if (!CollectionUtils.isEmpty(seriesMapping)) { + if (CollectionUtils.isNotEmpty(seriesMapping)) { this.seriesMapping.putAll(seriesMapping); } } diff --git a/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java b/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java index b94293775f31..19ba792e1651 100644 --- a/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java @@ -92,7 +92,7 @@ else if (statusCode.is5xxServerError()) { else { ex = new UnknownHttpStatusCodeException(message, statusCode.value(), statusText, headers, body, charset); } - if (!CollectionUtils.isEmpty(messageConverters)) { + if (CollectionUtils.isNotEmpty(messageConverters)) { ex.setBodyConvertFunction(initBodyConvertFunction(response, body, messageConverters)); } throw ex; @@ -101,7 +101,7 @@ else if (statusCode.is5xxServerError()) { @SuppressWarnings("NullAway") private static Function initBodyConvertFunction(ClientHttpResponse response, byte[] body, List> messageConverters) { - Assert.state(!CollectionUtils.isEmpty(messageConverters), "Expected message converters"); + Assert.state(CollectionUtils.isNotEmpty(messageConverters), "Expected message converters"); return resolvableType -> { try { HttpMessageConverterExtractor extractor = diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java index a6bbd0b68954..7d20aad61be9 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java @@ -291,7 +291,7 @@ private static void parseCommaDelimitedOrigin(String rawValue, Consumer */ public void setAllowedMethods(@Nullable List allowedMethods) { this.allowedMethods = (allowedMethods != null ? new ArrayList<>(allowedMethods) : null); - if (!CollectionUtils.isEmpty(allowedMethods)) { + if (CollectionUtils.isNotEmpty(allowedMethods)) { this.resolvedMethods = new ArrayList<>(allowedMethods.size()); for (String method : allowedMethods) { if (ALL.equals(method)) { @@ -601,7 +601,7 @@ public CorsConfiguration combine(@Nullable CorsConfiguration other) { CorsConfiguration config = new CorsConfiguration(this); List origins = combine(getAllowedOrigins(), other.getAllowedOrigins()); List patterns = combinePatterns(this.allowedOriginPatterns, other.allowedOriginPatterns); - config.allowedOrigins = (origins == DEFAULT_PERMIT_ALL && !CollectionUtils.isEmpty(patterns) ? null : origins); + config.allowedOrigins = (origins == DEFAULT_PERMIT_ALL && CollectionUtils.isNotEmpty(patterns) ? null : origins); config.allowedOriginPatterns = patterns; config.setAllowedMethods(combine(getAllowedMethods(), other.getAllowedMethods())); config.setAllowedHeaders(combine(getAllowedHeaders(), other.getAllowedHeaders())); diff --git a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java index 1210c18aeccc..137b93cf67b1 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java @@ -156,11 +156,11 @@ protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse r responseHeaders.setAccessControlAllowMethods(allowMethods); } - if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) { + if (preFlightRequest && CollectionUtils.isNotEmpty(allowHeaders)) { responseHeaders.setAccessControlAllowHeaders(allowHeaders); } - if (!CollectionUtils.isEmpty(config.getExposedHeaders())) { + if (CollectionUtils.isNotEmpty(config.getExposedHeaders())) { responseHeaders.setAccessControlExposeHeaders(config.getExposedHeaders()); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java index 90c579bdafe5..e2e6026d1bd3 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java @@ -153,11 +153,11 @@ protected boolean handleInternal(ServerWebExchange exchange, responseHeaders.setAccessControlAllowMethods(allowMethods); } - if (preFlightRequest && !CollectionUtils.isEmpty(allowHeaders)) { + if (preFlightRequest && CollectionUtils.isNotEmpty(allowHeaders)) { responseHeaders.setAccessControlAllowHeaders(allowHeaders); } - if (!CollectionUtils.isEmpty(config.getExposedHeaders())) { + if (CollectionUtils.isNotEmpty(config.getExposedHeaders())) { responseHeaders.setAccessControlExposeHeaders(config.getExposedHeaders()); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java index ea27c055563e..71ca39f955be 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java @@ -86,7 +86,7 @@ protected void doFilterInternal( throws ServletException, IOException { MultiValueMap params = parseIfNecessary(request); - if (!CollectionUtils.isEmpty(params)) { + if (CollectionUtils.isNotEmpty(params)) { filterChain.doFilter(new FormContentRequestWrapper(request, params), response); } else { diff --git a/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java b/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java index 18fc52357a29..44274341a119 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java +++ b/spring-web/src/main/java/org/springframework/web/filter/GenericFilterBean.java @@ -331,7 +331,7 @@ private static class FilterConfigPropertyValues extends MutablePropertyValues { public FilterConfigPropertyValues(FilterConfig config, Set requiredProperties) throws ServletException { - Set missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? + Set missingProps = (CollectionUtils.isNotEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration paramNames = config.getInitParameterNames(); @@ -345,7 +345,7 @@ public FilterConfigPropertyValues(FilterConfig config, Set requiredPrope } // Fail if we are still missing properties. - if (!CollectionUtils.isEmpty(missingProps)) { + if (CollectionUtils.isNotEmpty(missingProps)) { throw new ServletException( "Initialization from FilterConfig for filter '" + config.getFilterName() + "' failed; the following required properties were missing: " + diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java index d5b20179a242..d58d2c3d53ac 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java @@ -539,7 +539,7 @@ public HttpRequestValues build() { bodyValue = buildMultipartBody(); } - if (!CollectionUtils.isEmpty(this.requestParams)) { + if (CollectionUtils.isNotEmpty(this.requestParams)) { if (hasFormDataContentType()) { Assert.isTrue(!hasParts(), "Request parts not expected for a form data request"); Assert.isTrue(!hasBody(), "Body not expected for a form data request"); 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 d15e89e36970..284ce05ee7a2 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 @@ -432,7 +432,7 @@ public DefaultUriBuilder fragment(@Nullable String fragment) { @Override public URI build(Map uriVars) { - if (!CollectionUtils.isEmpty(defaultUriVariables)) { + if (CollectionUtils.isNotEmpty(defaultUriVariables)) { Map map = new HashMap<>(defaultUriVariables.size() + uriVars.size()); map.putAll(defaultUriVariables); map.putAll(uriVars); @@ -447,7 +447,7 @@ public URI build(Map uriVars) { @Override public URI build(@Nullable Object... uriVars) { - if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) { + if (ObjectUtils.isEmpty(uriVars) && CollectionUtils.isNotEmpty(defaultUriVariables)) { return build(Collections.emptyMap()); } if (encodingMode.equals(EncodingMode.VALUES_ONLY)) { 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 83a564638052..abc9dd53f104 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 @@ -211,14 +211,14 @@ public List getPathSegments() { StringBuilder queryBuilder = new StringBuilder(); this.queryParams.forEach((name, values) -> { if (CollectionUtils.isEmpty(values)) { - if (queryBuilder.length() != 0) { + if (StringUtils.hasLength(queryBuilder)) { queryBuilder.append('&'); } queryBuilder.append(name); } else { for (Object value : values) { - if (queryBuilder.length() != 0) { + if (StringUtils.hasLength(queryBuilder)) { queryBuilder.append('&'); } queryBuilder.append(name); @@ -482,7 +482,7 @@ public String toUriString() { } String path = getPath(); if (StringUtils.hasLength(path)) { - if (uriBuilder.length() != 0 && path.charAt(0) != PATH_DELIMITER) { + if (StringUtils.hasLength(uriBuilder) && path.charAt(0) != PATH_DELIMITER) { uriBuilder.append(PATH_DELIMITER); } uriBuilder.append(path); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java index cc3ae4dcf090..d2561c4bc84e 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java @@ -29,6 +29,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; /** * Representation of a URI template that can be expanded with URI variables via @@ -238,14 +239,14 @@ else if (c == '}') { } builder.append(c); } - if (builder.length() > 0) { + if (StringUtils.hasLength(builder)) { pattern.append(quote(builder)); } return new TemplateInfo(variableNames, Pattern.compile(pattern.toString())); } private static String quote(StringBuilder builder) { - return (builder.length() > 0 ? Pattern.quote(builder.toString()) : ""); + return (StringUtils.hasLength(builder) ? Pattern.quote(builder.toString()) : ""); } } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index ddd8ce9fc8a1..204e65b60297 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -567,7 +567,7 @@ else if (path1EndsWithSeparator || path2StartsWithSeparator) { * @return {@code true} has more than zero elements */ private boolean hasLength(@Nullable PathContainer container) { - return container != null && container.elements().size() > 0; + return container != null && CollectionUtils.isNotEmpty(container.elements()); } private static int scoreByNormalizedLength(PathPattern pattern) { diff --git a/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java b/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java index 17117c7d504c..2b718298fe33 100644 --- a/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java +++ b/spring-web/src/test/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequestTests.java @@ -24,6 +24,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import static org.assertj.core.api.Assertions.assertThat; @@ -81,7 +82,7 @@ private void insertQueryParams() { for (String key : this.queryParams.keySet()) { for (String value : this.queryParams.get(key)) { this.servletRequest.addParameter(key, value); - query.append(query.length() > 0 ? "&" : "").append(key).append('=').append(value); + query.append(StringUtils.hasLength(query) ? "&" : "").append(key).append('=').append(value); } } this.servletRequest.setQueryString(query.toString()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java index d2eb49ddbc2f..890d57d55a79 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/HeaderContentTypeResolver.java @@ -38,7 +38,7 @@ public List resolveMediaTypes(ServerWebExchange exchange) throws NotA try { List mediaTypes = exchange.getRequest().getHeaders().getAccept(); MimeTypeUtils.sortBySpecificity(mediaTypes); - return (!CollectionUtils.isEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST); + return (CollectionUtils.isNotEmpty(mediaTypes) ? mediaTypes : MEDIA_TYPE_ALL_LIST); } catch (InvalidMediaTypeException ex) { String value = exchange.getRequest().getHeaders().getFirst("Accept"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java index 769cd520653f..452a0e3c8dfe 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java @@ -49,7 +49,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport @Autowired(required = false) public void setConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.configurers.addWebFluxConfigurers(configurers); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java index f7b375ec433c..3fc19b8752d0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurerComposite.java @@ -46,7 +46,7 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer { public void addWebFluxConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.delegates.addAll(configurers); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index b09cb4628883..379acbd65b3f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -521,10 +521,10 @@ private void initHeaders(HttpHeaders out) { } private void initCookies(MultiValueMap out) { - if (!CollectionUtils.isEmpty(defaultCookies)) { + if (CollectionUtils.isNotEmpty(defaultCookies)) { out.putAll(defaultCookies); } - if (!CollectionUtils.isEmpty(this.cookies)) { + if (CollectionUtils.isNotEmpty(this.cookies)) { out.putAll(this.cookies); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java index 3704dcb8d092..115a24d5d42e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java @@ -521,7 +521,7 @@ protected boolean isInvalidPath(String path) { private @Nullable MediaType getMediaType(Resource resource) { MediaType mediaType = null; String filename = resource.getFilename(); - if (!CollectionUtils.isEmpty(this.mediaTypes)) { + if (CollectionUtils.isNotEmpty(this.mediaTypes)) { String ext = StringUtils.getFilenameExtension(filename); if (ext != null) { mediaType = this.mediaTypes.get(ext.toLowerCase(Locale.ROOT)); @@ -529,7 +529,7 @@ protected boolean isInvalidPath(String path) { } if (mediaType == null) { List mediaTypes = MediaTypeFactory.getMediaTypes(filename); - if (!CollectionUtils.isEmpty(mediaTypes)) { + if (CollectionUtils.isNotEmpty(mediaTypes)) { mediaType = mediaTypes.get(0); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java index fc32da4f9995..ff4f8c3ce952 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java @@ -207,7 +207,7 @@ public ConsumesRequestCondition combine(ConsumesRequestCondition other) { return EMPTY_CONDITION; } List result = getMatchingExpressions(exchange); - return !CollectionUtils.isEmpty(result) ? new ConsumesRequestCondition(result) : null; + return CollectionUtils.isNotEmpty(result) ? new ConsumesRequestCondition(result) : null; } private boolean hasBody(ServerHttpRequest request) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java index 78286280c7c9..b653b8fe6e8b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java @@ -202,7 +202,7 @@ public ProducesRequestCondition combine(ProducesRequestCondition other) { return this; } List result = getMatchingExpressions(exchange); - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return new ProducesRequestCondition(result, this); } else { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java index 9e8c7d8ddeff..0aeb7a91c7e2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java @@ -240,7 +240,7 @@ protected Mono writeBody(@Nullable Object body, MethodParameter bodyParame MediaType contentType = exchange.getResponse().getHeaders().getContentType(); boolean isPresentMediaType = (contentType != null && contentType.equals(bestMediaType)); Set producibleTypes = exchange.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); - if (isPresentMediaType || !CollectionUtils.isEmpty(producibleTypes)) { + if (isPresentMediaType || CollectionUtils.isNotEmpty(producibleTypes)) { return Mono.error(new HttpMessageNotWritableException( "No Encoder for [" + elementType + "] with preset Content-Type '" + contentType + "'")); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java index e72e2f9a09d8..82210624fea8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java @@ -83,7 +83,7 @@ public void setHeaderPredicate(Predicate headerPredicate) { public Mono> getValuesToBind(ServerWebExchange exchange) { return super.getValuesToBind(exchange).doOnNext(map -> { Map vars = exchange.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); - if (!CollectionUtils.isEmpty(vars)) { + if (CollectionUtils.isNotEmpty(vars)) { vars.forEach((key, value) -> addValueIfNotPresent(map, "URI variable", key, value)); } HttpHeaders headers = exchange.getRequest().getHeaders(); @@ -93,7 +93,7 @@ public Mono> getValuesToBind(ServerWebExchange exchange) { continue; } List values = entry.getValue(); - if (!CollectionUtils.isEmpty(values)) { + if (CollectionUtils.isNotEmpty(values)) { // For constructor args with @BindParam mapped to the actual header name addValueIfNotPresent(map, "Header", name, (values.size() == 1 ? values.get(0) : values)); // Also adapt to Java conventions for setters diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java index 0cf055921b65..4c028366f094 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HttpServletBean.java @@ -215,7 +215,7 @@ private static class ServletConfigPropertyValues extends MutablePropertyValues { public ServletConfigPropertyValues(ServletConfig config, Set requiredProperties) throws ServletException { - Set missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? + Set missingProps = (CollectionUtils.isNotEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration paramNames = config.getInitParameterNames(); @@ -229,7 +229,7 @@ public ServletConfigPropertyValues(ServletConfig config, Set requiredPro } // Fail if we are still missing properties. - if (!CollectionUtils.isEmpty(missingProps)) { + if (CollectionUtils.isNotEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java index 084aeb46658f..8f7e0c6aecd9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java @@ -50,7 +50,7 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { @Autowired(required = false) public void setConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.configurers.addWebMvcConfigurers(configurers); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java index 78ebf4f72fdc..5d6dbe96db5a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java @@ -114,7 +114,7 @@ private ContentNegotiatingViewResolver initContentNegotiatingViewResolver(View[] if (this.contentNegotiatingResolver != null) { if (!ObjectUtils.isEmpty(defaultViews) && - !CollectionUtils.isEmpty(this.contentNegotiatingResolver.getDefaultViews())) { + CollectionUtils.isNotEmpty(this.contentNegotiatingResolver.getDefaultViews())) { List views = new ArrayList<>(this.contentNegotiatingResolver.getDefaultViews()); views.addAll(Arrays.asList(defaultViews)); this.contentNegotiatingResolver.setDefaultViews(views); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java index c6dde088f229..302ec39cabe1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java @@ -44,7 +44,7 @@ class WebMvcConfigurerComposite implements WebMvcConfigurer { public void addWebMvcConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.delegates.addAll(configurers); } } 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 86b8bff446f5..79291fa971b3 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 @@ -383,7 +383,7 @@ private String getHandlerDescription(Object handler) { uriTemplateVariables.putAll(decodedVars); } } - if (logger.isTraceEnabled() && uriTemplateVariables.size() > 0) { + if (logger.isTraceEnabled() && CollectionUtils.isNotEmpty(uriTemplateVariables)) { logger.trace("URI variables " + uriTemplateVariables); } return buildPathExposingHandler(handler, bestMatch, pathWithinMapping, uriTemplateVariables); @@ -434,7 +434,7 @@ protected Object buildPathExposingHandler(Object rawHandler, String bestMatching HandlerExecutionChain chain = new HandlerExecutionChain(rawHandler); chain.addInterceptor(new PathExposingHandlerInterceptor(bestMatchingPattern, pathWithinMapping)); - if (!CollectionUtils.isEmpty(uriTemplateVariables)) { + if (CollectionUtils.isNotEmpty(uriTemplateVariables)) { chain.addInterceptor(new UriTemplateVariablesHandlerInterceptor(uriTemplateVariables)); } return chain; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java index 1212e7eb1a40..cb924625e69b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ParameterizableViewController.java @@ -23,6 +23,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; +import org.springframework.util.StringUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; import org.springframework.web.servlet.support.RequestContextUtils; @@ -187,7 +188,7 @@ private String formatStatusAndView() { sb.append("status=").append(this.statusCode); } if (this.view != null) { - sb.append(sb.length() != 0 ? ", " : ""); + sb.append(StringUtils.hasLength(sb) ? ", " : ""); String viewName = getViewName(); sb.append("view=").append(viewName != null ? "\"" + viewName + "\"" : this.view); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java index 8db32d3dfe94..9825d28aef6c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java @@ -220,7 +220,7 @@ public ConsumesRequestCondition combine(ConsumesRequestCondition other) { } List result = getMatchingExpressions(contentType); - return !CollectionUtils.isEmpty(result) ? new ConsumesRequestCondition(result) : null; + return CollectionUtils.isNotEmpty(result) ? new ConsumesRequestCondition(result) : null; } private boolean hasBody(HttpServletRequest request) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java index 83cc0abf0993..6683158e6e85 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java @@ -210,7 +210,7 @@ public ProducesRequestCondition combine(ProducesRequestCondition other) { return null; } List result = getMatchingExpressions(acceptedMediaTypes); - if (!CollectionUtils.isEmpty(result)) { + if (CollectionUtils.isNotEmpty(result)) { return new ProducesRequestCondition(result, this); } else if (MediaType.ALL.isPresentIn(acceptedMediaTypes)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index 0856a0db021d..892032df7fe6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -409,7 +409,7 @@ public List getParamConditions() { for (PartialMatch match : this.partialMatches) { if (match.hasProducesMatch()) { Set> set = match.getInfo().getParamsCondition().getExpressions(); - if (!CollectionUtils.isEmpty(set)) { + if (CollectionUtils.isNotEmpty(set)) { int i = 0; String[] array = new String[set.size()]; for (NameValueExpression expression : set) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java index d0e17b20f4d5..3078da41c788 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java @@ -360,7 +360,7 @@ selectedMediaType, outputMessage, getAdvice().determineWriteHints(body, returnTy (Set) inputMessage.getServletRequest() .getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); - if (isContentTypePreset || !CollectionUtils.isEmpty(producibleMediaTypes)) { + if (isContentTypePreset || CollectionUtils.isNotEmpty(producibleMediaTypes)) { throw new HttpMessageNotWritableException( "No converter for [" + valueType + "] with preset Content-Type '" + contentType + "'"); } @@ -423,7 +423,7 @@ protected List getProducibleMediaTypes( Set mediaTypes = (Set) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); - if (!CollectionUtils.isEmpty(mediaTypes)) { + if (CollectionUtils.isNotEmpty(mediaTypes)) { return new ArrayList<>(mediaTypes); } Set result = new LinkedHashSet<>(); @@ -542,7 +542,7 @@ private boolean safeExtension(HttpServletRequest request, @Nullable String exten if (extension.equals("html")) { String name = HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE; Set mediaTypes = (Set) request.getAttribute(name); - if (!CollectionUtils.isEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { + if (CollectionUtils.isNotEmpty(mediaTypes) && mediaTypes.contains(MediaType.TEXT_HTML)) { return true; } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java index ed86ade4da6e..3ca1a4bd58ac 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java @@ -305,7 +305,7 @@ private void saveFlashAttributes(ModelAndViewContainer mav, NativeWebRequest req ModelMap model = mav.getModel(); if (model instanceof RedirectAttributes redirectAttributes) { Map flashAttributes = redirectAttributes.getFlashAttributes(); - if (!CollectionUtils.isEmpty(flashAttributes)) { + if (CollectionUtils.isNotEmpty(flashAttributes)) { HttpServletRequest req = request.getNativeRequest(HttpServletRequest.class); HttpServletResponse res = request.getNativeResponse(HttpServletResponse.class); if (req != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java index 6783303a6b9d..2fb9c3164d97 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java @@ -63,7 +63,7 @@ public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC (Map) webRequest.getAttribute( HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); - if (!CollectionUtils.isEmpty(uriTemplateVars)) { + if (CollectionUtils.isNotEmpty(uriTemplateVars)) { return Collections.unmodifiableMap(uriTemplateVars); } else { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index dde3ef44ea62..a7e8d3013aff 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -764,7 +764,7 @@ private List getDefaultReturnValueHandlers() { } // Catch-all - if (!CollectionUtils.isEmpty(getModelAndViewResolvers())) { + if (CollectionUtils.isNotEmpty(getModelAndViewResolvers())) { handlers.add(new ModelAndViewResolverMethodReturnValueHandler(getModelAndViewResolvers())); } else { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index 8949b91d4134..7a8af204c02e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -653,7 +653,7 @@ protected boolean isInvalidPath(String path) { } if (mediaType == null) { List mediaTypes = MediaTypeFactory.getMediaTypes(filename); - if (!CollectionUtils.isEmpty(mediaTypes)) { + if (CollectionUtils.isNotEmpty(mediaTypes)) { mediaType = mediaTypes.get(0); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java index 10c50a093d50..6d78c6d31500 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java @@ -23,6 +23,7 @@ import org.jspecify.annotations.Nullable; import org.springframework.beans.PropertyAccessor; +import org.springframework.util.StringUtils; /** *

The {@code } tag supports and assists with nested beans or @@ -84,7 +85,7 @@ public void setPath(@Nullable String path) { if (path == null) { path = ""; } - if (path.length() > 0 && !path.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) { + if (StringUtils.hasLength(path) && !path.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) { path += PropertyAccessor.NESTED_PROPERTY_SEPARATOR; } this.path = path; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java index f40ec6cd327f..66f02361a254 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java @@ -446,7 +446,7 @@ protected void writeOptionalAttributes(TagWriter tagWriter) throws JspException writeOptionalAttribute(tagWriter, ONKEYUP_ATTRIBUTE, getOnkeyup()); writeOptionalAttribute(tagWriter, ONKEYDOWN_ATTRIBUTE, getOnkeydown()); - if (!CollectionUtils.isEmpty(this.dynamicAttributes)) { + if (CollectionUtils.isNotEmpty(this.dynamicAttributes)) { for (Map.Entry entry : this.dynamicAttributes.entrySet()) { tagWriter.writeOptionalAttributeValue(entry.getKey(), getDisplayString(entry.getValue())); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java index 954249268768..cfde7fe2764c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java @@ -681,7 +681,7 @@ public int doEndTag() throws JspException { * Writes the given values as hidden fields. */ private void writeHiddenFields(@Nullable Map hiddenFields) throws JspException { - if (!CollectionUtils.isEmpty(hiddenFields)) { + if (CollectionUtils.isNotEmpty(hiddenFields)) { Assert.state(this.tagWriter != null, "No TagWriter set"); this.tagWriter.appendValue("

\n"); for (Map.Entry entry : hiddenFields.entrySet()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java index dee083e47bc6..3752e3ea48e0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java @@ -277,7 +277,7 @@ public void afterPropertiesSet() { private List getProducibleMediaTypes(HttpServletRequest request) { Set mediaTypes = (Set) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); - if (!CollectionUtils.isEmpty(mediaTypes)) { + if (CollectionUtils.isNotEmpty(mediaTypes)) { return new ArrayList<>(mediaTypes); } else { @@ -322,7 +322,7 @@ private List getCandidateViews(String viewName, Locale locale, List viewResolvers) { this.viewResolvers.clear(); - if (!CollectionUtils.isEmpty(viewResolvers)) { + if (CollectionUtils.isNotEmpty(viewResolvers)) { this.viewResolvers.addAll(viewResolvers); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/JacksonJsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/JacksonJsonView.java index 6c2abcc89412..6bb3eb7bbb7b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/JacksonJsonView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/JacksonJsonView.java @@ -151,7 +151,7 @@ public void setExtractValueFromSingleKeyModel(boolean extractValueFromSingleKeyM @Override protected Object filterModel(Map model, HttpServletRequest request) { Map result = CollectionUtils.newHashMap(model.size()); - Set modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet()); + Set modelKeys = (CollectionUtils.isNotEmpty(this.modelKeys) ? this.modelKeys : model.keySet()); model.forEach((clazz, value) -> { if (!(value instanceof BindingResult) && modelKeys.contains(clazz) && !clazz.equals(JSON_VIEW_HINT) && diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java index 8e178e6c47f8..ca838597f2b6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java @@ -150,7 +150,7 @@ public void setExtractValueFromSingleKeyModel(boolean extractValueFromSingleKeyM @Override protected Object filterModel(Map model) { Map result = CollectionUtils.newHashMap(model.size()); - Set modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet()); + Set modelKeys = (CollectionUtils.isNotEmpty(this.modelKeys) ? this.modelKeys : model.keySet()); model.forEach((clazz, value) -> { if (!(value instanceof BindingResult) && modelKeys.contains(clazz) && !clazz.equals(JsonView.class.getName()) && diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java index 41b02ae4781d..72c84c5b2a78 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java @@ -72,7 +72,7 @@ public WebSocketExtension(String name) { public WebSocketExtension(String name, @Nullable Map parameters) { Assert.hasLength(name, "Extension name must not be empty"); this.name = name; - if (!CollectionUtils.isEmpty(parameters)) { + if (CollectionUtils.isNotEmpty(parameters)) { Map map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ROOT); map.putAll(parameters); this.parameters = Collections.unmodifiableMap(map); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java index 3183d349ed1d..2f9a16f0864e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java @@ -174,7 +174,7 @@ public void initializeNativeSession(Session session) { HttpHeaders headers = new HttpHeaders(); Map> nativeHeaders = session.getUpgradeRequest().getHeaders(); - if (!CollectionUtils.isEmpty(nativeHeaders)) { + if (CollectionUtils.isNotEmpty(nativeHeaders)) { headers.putAll(nativeHeaders); } this.headers = HttpHeaders.readOnlyHttpHeaders(headers); @@ -189,7 +189,7 @@ public void initializeNativeSession(Session session) { private List getExtensions(Session session) { List configs = session.getUpgradeResponse().getExtensions(); - if (!CollectionUtils.isEmpty(configs)) { + if (CollectionUtils.isNotEmpty(configs)) { List result = new ArrayList<>(configs.size()); for (ExtensionConfig config : configs) { result.add(new WebSocketExtension(config.getName(), config.getParameters())); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java index 5d75b369ab32..94dd31755687 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardWebSocketSession.java @@ -185,7 +185,7 @@ public void initializeNativeSession(Session session) { this.acceptedProtocol = session.getNegotiatedSubprotocol(); List standardExtensions = getNativeSession().getNegotiatedExtensions(); - if (!CollectionUtils.isEmpty(standardExtensions)) { + if (CollectionUtils.isNotEmpty(standardExtensions)) { this.extensions = new ArrayList<>(standardExtensions.size()); for (Extension standardExtension : standardExtensions) { this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension)); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.java index f70455f72f13..0f5879659e71 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.java @@ -40,7 +40,7 @@ public class DelegatingWebSocketConfiguration extends WebSocketConfigurationSupp @Autowired(required = false) public void setConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.configurers.addAll(configurers); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java index 50501f6d80f8..9aec1bb7c59b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java @@ -48,7 +48,7 @@ public class DelegatingWebSocketMessageBrokerConfiguration extends WebSocketMess @Autowired(required = false) public void setConfigurers(List configurers) { - if (!CollectionUtils.isEmpty(configurers)) { + if (CollectionUtils.isNotEmpty(configurers)) { this.configurers.addAll(configurers); } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java index 54fc2610ae6b..a9559b3ecbff 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java @@ -416,8 +416,8 @@ else if (sockJsPath.equals("/info")) { } else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) { - if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || - !CollectionUtils.isEmpty(getAllowedOriginPatterns())) { + if (CollectionUtils.isNotEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || + CollectionUtils.isNotEmpty(getAllowedOriginPatterns())) { if (requestInfo != null) { logger.debug("Iframe support is disabled when an origin check is required. " + "Ignoring transport request: " + requestInfo); @@ -648,7 +648,7 @@ public void handle(ServerHttpRequest request, ServerHttpResponse response) throw String etagValue = builder.toString(); List ifNoneMatch = request.getHeaders().getIfNoneMatch(); - if (!CollectionUtils.isEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) { + if (CollectionUtils.isNotEmpty(ifNoneMatch) && ifNoneMatch.get(0).equals(etagValue)) { response.setStatusCode(HttpStatus.NOT_MODIFIED); return; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java index ea0a1984cea8..9d44f5cd676d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/SockJsHttpRequestHandler.java @@ -30,6 +30,8 @@ import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.springframework.web.HttpRequestHandler; import org.springframework.web.context.ServletContextAware; import org.springframework.web.cors.CorsConfiguration; @@ -141,7 +143,7 @@ public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse private String getSockJsPath(HttpServletRequest servletRequest) { String attribute = HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE; String path = (String) servletRequest.getAttribute(attribute); - return (path.length() > 0 && path.charAt(0) != '/' ? "/" + path : path); + return (StringUtils.hasLength(path) && path.charAt(0) != '/' ? "/" + path : path); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java index bc145b049d6e..2c06a939a487 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/TransportHandlingSockJsService.java @@ -353,8 +353,8 @@ protected boolean validateRequest(String serverId, String sessionId, String tran return false; } - if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || - !CollectionUtils.isEmpty(getAllowedOriginPatterns())) { + if (CollectionUtils.isNotEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") || + CollectionUtils.isNotEmpty(getAllowedOriginPatterns())) { TransportType transportType = TransportType.fromValue(transport); if (transportType == null || !transportType.supportsOrigin()) { if (logger.isWarnEnabled()) {