From b63c853a7dc124d1bd25b8ead7d03dba727ed78a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:53:56 +0200 Subject: [PATCH 1/7] Upgrade to Tomcat 9.0.21, Undertow 2.0.21, RxJava 2.2.9, Checkstyle 8.21 Includes upgrade to Reactor Californium SR9 proper. --- build.gradle | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index abc7b2f466..ba261c551c 100644 --- a/build.gradle +++ b/build.gradle @@ -38,14 +38,14 @@ ext { kotlinVersion = "1.2.71" log4jVersion = "2.11.2" nettyVersion = "4.1.36.Final" - reactorVersion = "Californium-BUILD-SNAPSHOT" + reactorVersion = "Californium-SR9" rxjavaVersion = "1.3.8" rxjavaAdapterVersion = "1.2.1" - rxjava2Version = "2.2.8" + rxjava2Version = "2.2.9" slf4jVersion = "1.7.26" // spring-jcl + consistent 3rd party deps tiles3Version = "3.0.8" - tomcatVersion = "9.0.19" - undertowVersion = "2.0.20.Final" + tomcatVersion = "9.0.21" + undertowVersion = "2.0.21.Final" gradleScriptDir = "${rootProject.projectDir}/gradle" withoutJclOverSlf4J = { @@ -143,13 +143,12 @@ configure(allprojects) { project -> } checkstyle { - toolVersion = "8.20" + toolVersion = "8.21" configDir = rootProject.file("src/checkstyle") } repositories { maven { url "https://repo.spring.io/libs-release" } - maven { url "https://repo.spring.io/snapshot" } // Reactor mavenLocal() } From dec6d698192df28e6640d8de2c2745f7dd0c146d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:54:29 +0200 Subject: [PATCH 2/7] ReflectivePropertyAccessor uses interface methods if possible Closes gh-22242 --- .../expression/spel/support/ReflectivePropertyAccessor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 833e9fd6d9..3ef76790e9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.CompilablePropertyAccessor; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -413,7 +414,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { method.getParameterCount() == numberOfParams && (!mustBeStatic || Modifier.isStatic(method.getModifiers())) && (requiredReturnTypes.isEmpty() || requiredReturnTypes.contains(method.getReturnType()))) { - return method; + return ClassUtils.getInterfaceMethodIfPossible(method); } } } From fd159ad0821362ace61903be91ba897b24c6343a Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:56:30 +0200 Subject: [PATCH 3/7] Custom init/destroy methods get invoked through interface is possible Closes gh-22939 --- .../AbstractAutowireCapableBeanFactory.java | 7 ++++--- .../factory/support/DisposableBeanAdapter.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index fe10c1654b..caa76ad260 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -1860,7 +1860,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac String initMethodName = mbd.getInitMethodName(); Assert.state(initMethodName != null, "No init method set"); - final Method initMethod = (mbd.isNonPublicAccessAllowed() ? + Method initMethod = (mbd.isNonPublicAccessAllowed() ? BeanUtils.findMethod(bean.getClass(), initMethodName) : ClassUtils.getMethodIfAvailable(bean.getClass(), initMethodName)); @@ -1882,15 +1882,16 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac if (logger.isTraceEnabled()) { logger.trace("Invoking init method '" + initMethodName + "' on bean with name '" + beanName + "'"); } + Method methodToInvoke = ClassUtils.getInterfaceMethodIfPossible(initMethod); if (System.getSecurityManager() != null) { AccessController.doPrivileged((PrivilegedAction) () -> { - ReflectionUtils.makeAccessible(initMethod); + ReflectionUtils.makeAccessible(methodToInvoke); return null; }); try { AccessController.doPrivileged((PrivilegedExceptionAction) () -> - initMethod.invoke(bean), getAccessControlContext()); + methodToInvoke.invoke(bean), getAccessControlContext()); } catch (PrivilegedActionException pae) { InvocationTargetException ex = (InvocationTargetException) pae.getException(); 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 e8fc4ce2d7..9d1ce3466c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,15 +112,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { if (destroyMethodName != null && !(this.invokeDisposableBean && "destroy".equals(destroyMethodName)) && !beanDefinition.isExternallyManagedDestroyMethod(destroyMethodName)) { this.destroyMethodName = destroyMethodName; - this.destroyMethod = determineDestroyMethod(destroyMethodName); - if (this.destroyMethod == null) { + Method destroyMethod = determineDestroyMethod(destroyMethodName); + if (destroyMethod == null) { if (beanDefinition.isEnforceDestroyMethod()) { throw new BeanDefinitionValidationException("Could not find a destroy method named '" + destroyMethodName + "' on bean with name '" + beanName + "'"); } } else { - Class[] paramTypes = this.destroyMethod.getParameterTypes(); + Class[] paramTypes = destroyMethod.getParameterTypes(); if (paramTypes.length > 1) { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has more than one parameter - not supported as destroy method"); @@ -129,7 +129,9 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" + beanName + "' has a non-boolean parameter - not supported as destroy method"); } + destroyMethod = ClassUtils.getInterfaceMethodIfPossible(destroyMethod); } + this.destroyMethod = destroyMethod; } this.beanPostProcessors = filterPostProcessors(postProcessors, bean); } @@ -271,9 +273,9 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { invokeCustomDestroyMethod(this.destroyMethod); } else if (this.destroyMethodName != null) { - Method methodToCall = determineDestroyMethod(this.destroyMethodName); - if (methodToCall != null) { - invokeCustomDestroyMethod(methodToCall); + Method methodToInvoke = determineDestroyMethod(this.destroyMethodName); + if (methodToInvoke != null) { + invokeCustomDestroyMethod(ClassUtils.getInterfaceMethodIfPossible(methodToInvoke)); } } } From b37390b8fedc722e8f152123b92e1ad5fc7c34f7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:56:41 +0200 Subject: [PATCH 4/7] Restore javax meta-annotation lookup behavior Closes gh-22957 --- spring-core/spring-core.gradle | 1 + .../core/annotation/AnnotationUtils.java | 2 +- .../AnnotatedElementUtilsTests.java | 67 +++++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/spring-core/spring-core.gradle b/spring-core/spring-core.gradle index 685f18de2f..bda90aad82 100644 --- a/spring-core/spring-core.gradle +++ b/spring-core/spring-core.gradle @@ -80,6 +80,7 @@ dependencies { optional("io.netty:netty-buffer") testCompile("io.projectreactor:reactor-test") testCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}") + testCompile("com.google.code.findbugs:jsr305:3.0.2") testCompile("org.xmlunit:xmlunit-matchers:2.6.2") testCompile("javax.xml.bind:jaxb-api:2.3.1") testCompile("com.fasterxml.woodstox:woodstox-core:5.2.0") { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 8a54477466..2280729ec0 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -956,7 +956,7 @@ public abstract class AnnotationUtils { return false; } String name = clazz.getName(); - return (name.startsWith("java") || name.startsWith("org.springframework.lang.")); + return (name.startsWith("java.") || name.startsWith("org.springframework.lang.")); } /** diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index 80f6a133c6..eb1298f52d 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; @@ -28,7 +29,10 @@ import java.lang.reflect.Method; import java.util.Date; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.Resource; +import javax.annotation.meta.When; import org.junit.Ignore; import org.junit.Rule; @@ -36,6 +40,7 @@ import org.junit.Test; import org.junit.internal.ArrayComparisonFailure; import org.junit.rules.ExpectedException; +import org.springframework.lang.NonNullApi; import org.springframework.stereotype.Component; import org.springframework.stereotype.Indexed; import org.springframework.util.Assert; @@ -118,6 +123,14 @@ public class AnnotatedElementUtilsTests { assertFalse(hasMetaAnnotationTypes(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class.getName())); } + @Test + public void isAnnotatedForPlainTypes() { + assertTrue(isAnnotated(Order.class, Documented.class)); + assertTrue(isAnnotated(NonNullApi.class, Documented.class)); + assertTrue(isAnnotated(NonNullApi.class, Nonnull.class)); + assertTrue(isAnnotated(ParametersAreNonnullByDefault.class, Nonnull.class)); + } + @Test public void isAnnotatedOnNonAnnotatedClass() { assertFalse(isAnnotated(NonAnnotatedClass.class, TX_NAME)); @@ -147,6 +160,14 @@ public class AnnotatedElementUtilsTests { assertTrue(isAnnotated(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class.getName())); } + @Test + public void hasAnnotationForPlainTypes() { + assertTrue(hasAnnotation(Order.class, Documented.class)); + assertTrue(hasAnnotation(NonNullApi.class, Documented.class)); + assertTrue(hasAnnotation(NonNullApi.class, Nonnull.class)); + assertTrue(hasAnnotation(ParametersAreNonnullByDefault.class, Nonnull.class)); + } + @Test public void getAllAnnotationAttributesOnNonAnnotatedClass() { assertNull(getAllAnnotationAttributes(NonAnnotatedClass.class, TX_NAME)); @@ -207,6 +228,22 @@ public class AnnotatedElementUtilsTests { attributes.get("value")); } + @Test + public void getAllAnnotationAttributesOnLangType() { + MultiValueMap attributes = getAllAnnotationAttributes( + NonNullApi.class, Nonnull.class.getName()); + assertNotNull(attributes); + assertEquals(asList(When.ALWAYS), attributes.get("when")); + } + + @Test + public void getAllAnnotationAttributesOnJavaxType() { + MultiValueMap attributes = getAllAnnotationAttributes( + ParametersAreNonnullByDefault.class, Nonnull.class.getName()); + assertNotNull(attributes); + assertEquals(asList(When.ALWAYS), attributes.get("when")); + } + @Test public void getMergedAnnotationAttributesOnClassWithLocalAnnotation() { Class element = TxConfig.class; @@ -701,14 +738,33 @@ public class AnnotatedElementUtilsTests { @Test public void javaLangAnnotationTypeViaFindMergedAnnotation() throws Exception { Constructor deprecatedCtor = Date.class.getConstructor(String.class); - assertEquals(deprecatedCtor.getAnnotation(Deprecated.class), findMergedAnnotation(deprecatedCtor, Deprecated.class)); - assertEquals(Date.class.getAnnotation(Deprecated.class), findMergedAnnotation(Date.class, Deprecated.class)); + assertEquals(deprecatedCtor.getAnnotation(Deprecated.class), + findMergedAnnotation(deprecatedCtor, Deprecated.class)); + assertEquals(Date.class.getAnnotation(Deprecated.class), + findMergedAnnotation(Date.class, Deprecated.class)); } @Test public void javaxAnnotationTypeViaFindMergedAnnotation() throws Exception { - assertEquals(ResourceHolder.class.getAnnotation(Resource.class), findMergedAnnotation(ResourceHolder.class, Resource.class)); - assertEquals(SpringAppConfigClass.class.getAnnotation(Resource.class), findMergedAnnotation(SpringAppConfigClass.class, Resource.class)); + assertEquals(ResourceHolder.class.getAnnotation(Resource.class), + findMergedAnnotation(ResourceHolder.class, Resource.class)); + assertEquals(SpringAppConfigClass.class.getAnnotation(Resource.class), + findMergedAnnotation(SpringAppConfigClass.class, Resource.class)); + } + + @Test + public void javaxMetaAnnotationTypeViaFindMergedAnnotation() throws Exception { + assertEquals(ParametersAreNonnullByDefault.class.getAnnotation(Nonnull.class), + findMergedAnnotation(ParametersAreNonnullByDefault.class, Nonnull.class)); + assertEquals(ParametersAreNonnullByDefault.class.getAnnotation(Nonnull.class), + findMergedAnnotation(ResourceHolder.class, Nonnull.class)); + } + + @Test + public void nullableAnnotationTypeViaFindMergedAnnotation() throws Exception { + Method method = TransactionalServiceImpl.class.getMethod("doIt"); + assertEquals(method.getAnnotation(Resource.class), findMergedAnnotation(method, Resource.class)); + assertEquals(method.getAnnotation(Resource.class), findMergedAnnotation(method, Resource.class)); } @Test @@ -1288,6 +1344,7 @@ public class AnnotatedElementUtilsTests { } @Resource(name = "x") + @ParametersAreNonnullByDefault static class ResourceHolder { } From 4fc97475694945b3949596a451b4d26f8cbb6def Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:56:57 +0200 Subject: [PATCH 5/7] Defensive concurrent access to key set from java.util.Properties Closes gh-23063 --- .../core/env/PropertiesPropertySource.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertiesPropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertiesPropertySource.java index 0d023fe336..d09c368351 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertiesPropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertiesPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ import java.util.Properties; */ public class PropertiesPropertySource extends MapPropertySource { - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public PropertiesPropertySource(String name, Properties source) { super(name, (Map) source); } @@ -44,4 +44,12 @@ public class PropertiesPropertySource extends MapPropertySource { super(name, source); } + + @Override + public String[] getPropertyNames() { + synchronized (this.source) { + return super.getPropertyNames(); + } + } + } From 1956cb1e57aa0574bf18af3399dc25a5dfaeb1dd Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:57:17 +0200 Subject: [PATCH 6/7] Defensive concurrent access to shared file extension data structures Closes gh-23064 --- ...MappingMediaTypeFileExtensionResolver.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 6b7208bc3c..f6ec22df6e 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,10 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArrayList; import org.springframework.http.MediaType; import org.springframework.lang.Nullable; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; /** * An implementation of {@code MediaTypeFileExtensionResolver} that maintains @@ -37,15 +36,16 @@ import org.springframework.util.MultiValueMap; * Subsequently subclasses can use {@link #addMapping} to add more mappings. * * @author Rossen Stoyanchev + * @author Juergen Hoeller * @since 3.2 */ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExtensionResolver { private final ConcurrentMap mediaTypes = new ConcurrentHashMap<>(64); - private final MultiValueMap fileExtensions = new LinkedMultiValueMap<>(); + private final ConcurrentMap> fileExtensions = new ConcurrentHashMap<>(64); - private final List allFileExtensions = new ArrayList<>(); + private final List allFileExtensions = new CopyOnWriteArrayList<>(); /** @@ -53,12 +53,14 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten */ public MappingMediaTypeFileExtensionResolver(@Nullable Map mediaTypes) { if (mediaTypes != null) { + List allFileExtensions = new ArrayList<>(); mediaTypes.forEach((extension, mediaType) -> { String lowerCaseExtension = extension.toLowerCase(Locale.ENGLISH); this.mediaTypes.put(lowerCaseExtension, mediaType); - this.fileExtensions.add(mediaType, lowerCaseExtension); - this.allFileExtensions.add(lowerCaseExtension); + addFileExtension(mediaType, extension); + allFileExtensions.add(lowerCaseExtension); }); + this.allFileExtensions.addAll(allFileExtensions); } } @@ -77,11 +79,17 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten protected void addMapping(String extension, MediaType mediaType) { MediaType previous = this.mediaTypes.putIfAbsent(extension, mediaType); if (previous == null) { - this.fileExtensions.add(mediaType, extension); + addFileExtension(mediaType, extension); this.allFileExtensions.add(extension); } } + private void addFileExtension(MediaType mediaType, String extension) { + List newList = new CopyOnWriteArrayList<>(); + List oldList = this.fileExtensions.putIfAbsent(mediaType, newList); + (oldList != null ? oldList : newList).add(extension); + } + @Override public List resolveFileExtensions(MediaType mediaType) { From 7dc92aa05deba53a297c5278dd27ce21d40eed9b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 11 Jun 2019 20:57:27 +0200 Subject: [PATCH 7/7] Polishing --- .../springframework/beans/PropertyValue.java | 6 ++-- .../beans/factory/InjectionPoint.java | 2 +- .../factory/config/BeanDefinitionVisitor.java | 6 ++-- .../factory/config/RuntimeBeanReference.java | 18 +++++------ .../factory/config/YamlMapFactoryBean.java | 6 ++-- .../config/YamlPropertiesFactoryBean.java | 4 +-- .../support/AbstractBeanDefinition.java | 2 +- .../factory/support/AbstractBeanFactory.java | 4 +-- .../support/BeanDefinitionBuilder.java | 6 ++-- .../support/BeanDefinitionValueResolver.java | 8 ++--- ...CglibSubclassingInstantiationStrategy.java | 4 +-- .../support/BeanDefinitionBuilderTests.java | 12 ++++--- .../tests/sample/beans/TestBean.java | 4 +-- .../SimpleApplicationEventMulticaster.java | 2 +- .../core/CollectionFactory.java | 4 +-- .../IntegerToEnumConverterFactory.java | 4 +-- .../support/StringToEnumConverterFactory.java | 2 +- .../core/env/AbstractEnvironment.java | 6 ++-- .../core/env/StandardEnvironment.java | 8 +++-- .../expression/spel/ast/TypeCode.java | 5 ++- .../ReflectiveConstructorResolver.java | 4 +-- .../spel/support/StandardTypeComparator.java | 31 +++---------------- .../core/PreparedStatementCreatorFactory.java | 4 +-- .../jms/support/SimpleJmsHeaderMapper.java | 9 +++--- .../context/cache/DefaultContextCache.java | 8 ++--- .../test/web/ModelAndViewAssert.java | 4 +-- .../request/async/WebAsyncManager.java | 4 +-- .../method/annotation/MapMethodProcessor.java | 4 +-- .../annotation/SessionAttributesHandler.java | 5 ++- .../web/servlet/view/RedirectView.java | 2 +- 30 files changed, 82 insertions(+), 106 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java index e64227fdd3..d921a33ada 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -169,7 +169,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri } /** - * Set the converted value of the constructor argument, + * Set the converted value of this property value, * after processed type conversion. */ public synchronized void setConvertedValue(@Nullable Object value) { @@ -178,7 +178,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri } /** - * Return the converted value of the constructor argument, + * Return the converted value of this property value, * after processed type conversion. */ @Nullable diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java b/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java index 39497f5f07..7441687422 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java @@ -180,7 +180,7 @@ public class InjectionPoint { if (this == other) { return true; } - if (getClass() != other.getClass()) { + if (other == null || getClass() != other.getClass()) { return false; } InjectionPoint otherPoint = (InjectionPoint) other; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java index 6e71a0572e..a0fae36c9b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java @@ -234,7 +234,7 @@ public class BeanDefinitionVisitor { } } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) protected void visitList(List listVal) { for (int i = 0; i < listVal.size(); i++) { Object elem = listVal.get(i); @@ -245,7 +245,7 @@ public class BeanDefinitionVisitor { } } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) protected void visitSet(Set setVal) { Set newContent = new LinkedHashSet(); boolean entriesModified = false; @@ -262,7 +262,7 @@ public class BeanDefinitionVisitor { } } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) protected void visitMap(Map mapVal) { Map newContent = new LinkedHashMap(); boolean entriesModified = false; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java index 2f685984fb..ec8aa5c140 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.util.Assert; * @author Rod Johnson * @author Juergen Hoeller * @see BeanDefinition#getPropertyValues() - * @see org.springframework.beans.factory.BeanFactory#getBean + * @see org.springframework.beans.factory.BeanFactory#getBean(String) */ public class RuntimeBeanReference implements BeanReference { @@ -39,9 +39,7 @@ public class RuntimeBeanReference implements BeanReference { /** - * Create a new RuntimeBeanReference to the given bean name, - * without explicitly marking it as reference to a bean in - * the parent factory. + * Create a new RuntimeBeanReference to the given bean name. * @param beanName name of the target bean */ public RuntimeBeanReference(String beanName) { @@ -50,11 +48,10 @@ public class RuntimeBeanReference implements BeanReference { /** * Create a new RuntimeBeanReference to the given bean name, - * with the option to mark it as reference to a bean in - * the parent factory. + * with the option to mark it as reference to a bean in the parent factory. * @param beanName name of the target bean - * @param toParent whether this is an explicit reference to - * a bean in the parent factory + * @param toParent whether this is an explicit reference to a bean in the + * parent factory */ public RuntimeBeanReference(String beanName, boolean toParent) { Assert.hasText(beanName, "'beanName' must not be empty"); @@ -69,8 +66,7 @@ public class RuntimeBeanReference implements BeanReference { } /** - * Return whether this is an explicit reference to a bean - * in the parent factory. + * Return whether this is an explicit reference to a bean in the parent factory. */ public boolean isToParent() { return this.toParent; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java index 1e20063ccc..bc77a9f7c1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,7 +117,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBeanThe default implementation returns the merged {@code Map} instance. * @return the object returned by this factory - * @see #process(java.util.Map, MatchCallback) + * @see #process(MatchCallback) */ protected Map createMap() { Map result = new LinkedHashMap<>(); @@ -125,7 +125,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean output, Map map) { map.forEach((key, value) -> { Object existing = output.get(key); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java index 200f78c4c9..71088f17f0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -128,7 +128,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB *

Invoked lazily the first time {@link #getObject()} is invoked in * case of a shared singleton; else, on each {@link #getObject()} call. * @return the object returned by this factory - * @see #process(MatchCallback) () + * @see #process(MatchCallback) */ protected Properties createProperties() { Properties result = CollectionFactory.createStringAdaptingProperties(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java index f28218afd8..4a10cdb155 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java @@ -65,7 +65,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess public static final String SCOPE_DEFAULT = ""; /** - * Constant that indicates no autowiring at all. + * Constant that indicates no external autowiring at all. * @see #setAutowireMode */ public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 640e712e89..e6fcceb9e4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1648,7 +1648,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp return beanInstance; } if (!(beanInstance instanceof FactoryBean)) { - throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass()); + throw new BeanIsNotAFactoryException(beanName, beanInstance.getClass()); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java index 2b04fb155e..cfddff43e0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,6 +180,8 @@ public final class BeanDefinitionBuilder { /** * Set the name of a non-static factory method to use for this definition, * including the bean name of the factory instance to call the method on. + * @param factoryMethod the name of the factory method + * @param factoryBean the name of the bean to call the specified factory method on * @since 4.3.6 */ public BeanDefinitionBuilder setFactoryMethodOnBean(String factoryMethod, String factoryBean) { @@ -209,7 +211,7 @@ public final class BeanDefinitionBuilder { } /** - * Add the supplied property value under the given name. + * Add the supplied property value under the given property name. */ public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value) { this.beanDefinition.getPropertyValues().add(name, value); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java index 776a610ea0..e3e7780105 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -385,8 +385,7 @@ class BeanDefinitionValueResolver { private Object resolveManagedArray(Object argName, List ml, Class elementType) { Object resolved = Array.newInstance(elementType, ml.size()); for (int i = 0; i < ml.size(); i++) { - Array.set(resolved, i, - resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i))); + Array.set(resolved, i, resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i))); } return resolved; } @@ -397,8 +396,7 @@ class BeanDefinitionValueResolver { private List resolveManagedList(Object argName, List ml) { List resolved = new ArrayList<>(ml.size()); for (int i = 0; i < ml.size(); i++) { - resolved.add( - resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i))); + resolved.add(resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i))); } return resolved; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java index 6e874eb551..60e8a11672 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -176,7 +176,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt @Override public boolean equals(Object other) { - return (getClass() == other.getClass() && + return (other != null && getClass() == other.getClass() && this.beanDefinition.equals(((CglibIdentitySupport) other).beanDefinition)); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java index c9d347e28b..243cf07540 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,9 @@ import org.junit.Test; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.tests.sample.beans.TestBean; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Rod Johnson @@ -36,9 +38,9 @@ public class BeanDefinitionBuilderTests { String[] dependsOn = new String[] { "A", "B", "C" }; BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE); - bdb.addPropertyReference("age", "15"); - for (int i = 0; i < dependsOn.length; i++) { - bdb.addDependsOn(dependsOn[i]); + bdb.addPropertyValue("age", "15"); + for (String dependsOnEntry : dependsOn) { + bdb.addDependsOn(dependsOnEntry); } RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition(); diff --git a/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java b/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java index 3425c43389..1e83a21a13 100644 --- a/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java +++ b/spring-beans/src/test/java/org/springframework/tests/sample/beans/TestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,8 +61,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt private ITestBean spouse; - protected ITestBean[] spouses; - private String touchy; private String[] stringArray; diff --git a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java index 952113e88f..34ae5372d4 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java @@ -166,7 +166,7 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM } } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) private void doInvokeListener(ApplicationListener listener, ApplicationEvent event) { try { listener.onApplicationEvent(event); diff --git a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java index 4923464910..80cbb3df91 100644 --- a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java @@ -241,7 +241,7 @@ public final class CollectionFactory { * @see java.util.TreeMap * @see java.util.LinkedHashMap */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public static Map createApproximateMap(@Nullable Object map, int capacity) { if (map instanceof EnumMap) { EnumMap enumMap = new EnumMap((EnumMap) map); @@ -294,7 +294,7 @@ public final class CollectionFactory { * {@code null}; or if the desired {@code mapType} is {@link EnumMap} and * the supplied {@code keyType} is not a subtype of {@link Enum} */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public static Map createMap(Class mapType, @Nullable Class keyType, int capacity) { Assert.notNull(mapType, "Map type must not be null"); if (mapType.isInterface()) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/IntegerToEnumConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/IntegerToEnumConverterFactory.java index 8d56edee3f..e05bfe34c5 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/IntegerToEnumConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/IntegerToEnumConverterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.core.convert.converter.ConverterFactory; * @author Stephane Nicoll * @since 4.3 */ -@SuppressWarnings({"unchecked", "rawtypes"}) +@SuppressWarnings({"rawtypes", "unchecked"}) final class IntegerToEnumConverterFactory implements ConverterFactory { @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java index 5e45e62d48..e79f62dccd 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java @@ -26,7 +26,7 @@ import org.springframework.core.convert.converter.ConverterFactory; * @author Stephane Nicoll * @since 3.0 */ -@SuppressWarnings({"unchecked", "rawtypes"}) +@SuppressWarnings({"rawtypes", "unchecked"}) final class StringToEnumConverterFactory implements ConverterFactory { @Override diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index 1d69b41ac4..e13e03ed0f 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -383,7 +383,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public Map getSystemProperties() { try { return (Map) System.getProperties(); @@ -409,7 +409,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public Map getSystemEnvironment() { if (suppressGetenvAccess()) { return Collections.emptyMap(); diff --git a/spring-core/src/main/java/org/springframework/core/env/StandardEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/StandardEnvironment.java index 179e1d7b5a..fc4570684d 100644 --- a/spring-core/src/main/java/org/springframework/core/env/StandardEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/StandardEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,8 +75,10 @@ public class StandardEnvironment extends AbstractEnvironment { */ @Override protected void customizePropertySources(MutablePropertySources propertySources) { - propertySources.addLast(new MapPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties())); - propertySources.addLast(new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment())); + propertySources.addLast( + new PropertiesPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties())); + propertySources.addLast( + new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment())); } } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java index 8a252f9309..aabc43d0b2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeCode.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,10 +84,9 @@ public enum TypeCode { public static TypeCode forName(String name) { - String searchingFor = name.toUpperCase(); TypeCode[] tcs = values(); for (int i = 1; i < tcs.length; i++) { - if (tcs[i].name().equals(searchingFor)) { + if (tcs[i].name().equalsIgnoreCase(name)) { return tcs[i]; } } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java index 667e4c18b8..82a307f6b9 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public class ReflectiveConstructorResolver implements ConstructorResolver { Arrays.sort(ctors, (c1, c2) -> { int c1pl = c1.getParameterCount(); int c2pl = c2.getParameterCount(); - return (c1pl < c2pl ? -1 : (c1pl > c2pl ? 1 : 0)); + return Integer.compare(c1pl, c2pl); }); Constructor closeMatch = null; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java index 94b5b25d57..e2e6d11c7f 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,20 +83,16 @@ public class StandardTypeComparator implements TypeComparator { return leftBigInteger.compareTo(rightBigInteger); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { - // Don't call Long.compare here - only available on JDK 1.7+ - return compare(leftNumber.longValue(), rightNumber.longValue()); + return Long.compare(leftNumber.longValue(), rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { - // Don't call Integer.compare here - only available on JDK 1.7+ - return compare(leftNumber.intValue(), rightNumber.intValue()); + return Integer.compare(leftNumber.intValue(), rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { - // Don't call Short.compare here - only available on JDK 1.7+ - return compare(leftNumber.shortValue(), rightNumber.shortValue()); + return leftNumber.shortValue() - rightNumber.shortValue(); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { - // Don't call Short.compare here - only available on JDK 1.7+ - return compare(leftNumber.byteValue(), rightNumber.byteValue()); + return leftNumber.byteValue() - rightNumber.byteValue(); } else { // Unknown Number subtypes -> best guess is double multiplication @@ -116,21 +112,4 @@ public class StandardTypeComparator implements TypeComparator { throw new SpelEvaluationException(SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass()); } - - private static int compare(long x, long y) { - return (x < y ? -1 : (x > y ? 1 : 0)); - } - - private static int compare(int x, int y) { - return (x < y ? -1 : (x > y ? 1 : 0)); - } - - private static int compare(short x, short y) { - return x - y; - } - - private static int compare(byte x, byte y) { - return x - y; - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java index 3e18a956cb..9830abdafe 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -272,7 +272,7 @@ public class PreparedStatementCreatorFactory { Collection entries = (Collection) in; for (Object entry : entries) { if (entry instanceof Object[]) { - Object[] valueArray = ((Object[])entry); + Object[] valueArray = (Object[]) entry; for (Object argValue : valueArray) { StatementCreatorUtils.setParameterValue(ps, sqlColIndx++, declaredParameter, argValue); } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/SimpleJmsHeaderMapper.java b/spring-jms/src/main/java/org/springframework/jms/support/SimpleJmsHeaderMapper.java index a5fba5a00d..80954b6878 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/SimpleJmsHeaderMapper.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/SimpleJmsHeaderMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,10 +92,11 @@ public class SimpleJmsHeaderMapper extends AbstractHeaderMapper impleme logger.debug("Failed to set JMSType - skipping", ex); } } - Set headerNames = headers.keySet(); - for (String headerName : headerNames) { + Set> entries = headers.entrySet(); + for (Map.Entry entry : entries) { + String headerName = entry.getKey(); if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) { - Object value = headers.get(headerName); + Object value = entry.getValue(); if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) { try { String propertyName = this.fromHeaderName(headerName); diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java index c639ef71e2..9a20524958 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,9 +180,9 @@ public class DefaultContextCache implements ContextCache { } // Remove empty entries from the hierarchy map. - for (MergedContextConfiguration currentKey : this.hierarchyMap.keySet()) { - if (this.hierarchyMap.get(currentKey).isEmpty()) { - this.hierarchyMap.remove(currentKey); + for (Map.Entry> entry : this.hierarchyMap.entrySet()) { + if (entry.getValue().isEmpty()) { + this.hierarchyMap.remove(entry.getKey()); } } } 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 e7456f3f9a..f3415671bf 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,7 +142,7 @@ public abstract class ModelAndViewAssert { * @param comparator the comparator to use (may be {@code null}). If not * specifying the comparator, both lists will be sorted not using any comparator. */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public static void assertSortAndCompareListModelAttribute( ModelAndView mav, String modelName, List expectedList, Comparator comparator) { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java index 09df60896e..bf20dc472e 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -253,7 +253,7 @@ public final class WebAsyncManager { * @see #getConcurrentResult() * @see #getConcurrentResultContext() */ - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public void startCallableProcessing(Callable callable, Object... processingContext) throws Exception { Assert.notNull(callable, "Callable must not be null"); startCallableProcessing(new WebAsyncTask(callable), processingContext); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index a9f921ced5..ea505d276b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,7 +60,7 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({"rawtypes", "unchecked"}) public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java index 287abc112e..9acbe85ec0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,8 +113,7 @@ class SessionAttributesHandler { * @param attributes candidate attributes for session storage */ public void storeAttributes(WebSession session, Map attributes) { - attributes.keySet().forEach(name -> { - Object value = attributes.get(name); + attributes.forEach((name, value) -> { if (value != null && isHandlerSessionAttribute(name, value.getClass())) { session.getAttributes().put(name, value); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java index 77313e7cee..15dbca40ef 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java @@ -390,7 +390,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { result.append(UriUtils.encodePathSegment(value.toString(), encodingScheme)); endLastMatch = matcher.end(); } - result.append(targetUrl.substring(endLastMatch, targetUrl.length())); + result.append(targetUrl.substring(endLastMatch)); return result; }