From 5846d9c2eae4644955f3b3ac39efe7af5a049490 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Jul 2020 17:44:59 +0200 Subject: [PATCH 1/5] Clarify enforceInitMethod/enforceDestroyMethod default values Closes gh-25402 --- .../support/AbstractBeanDefinition.java | 18 +++++++++++++----- .../support/BeanDefinitionDefaults.java | 14 +++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) 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 0fa9a6a5514..c30bc3271a1 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 @@ -945,16 +945,20 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess } /** - * Specify whether or not the configured init method is the default. - *

The default value is {@code false}. + * Specify whether or not the configured initializer method is the default. + *

The default value is {@code true} for a locally specified init method + * but switched to {@code false} for a shared setting in a defaults section + * (e.g. {@code bean init-method} versus {@code beans default-init-method} + * level in XML) which might not apply to all contained bean definitions. * @see #setInitMethodName + * @see #applyDefaults */ public void setEnforceInitMethod(boolean enforceInitMethod) { this.enforceInitMethod = enforceInitMethod; } /** - * Indicate whether the configured init method is the default. + * Indicate whether the configured initializer method is the default. * @see #getInitMethodName() */ public boolean isEnforceInitMethod() { @@ -981,8 +985,12 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Specify whether or not the configured destroy method is the default. - *

The default value is {@code false}. + *

The default value is {@code true} for a locally specified destroy method + * but switched to {@code false} for a shared setting in a defaults section + * (e.g. {@code bean destroy-method} versus {@code beans default-destroy-method} + * level in XML) which might not apply to all contained bean definitions. * @see #setDestroyMethodName + * @see #applyDefaults */ public void setEnforceDestroyMethod(boolean enforceDestroyMethod) { this.enforceDestroyMethod = enforceDestroyMethod; @@ -990,7 +998,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Indicate whether the configured destroy method is the default. - * @see #getDestroyMethodName + * @see #getDestroyMethodName() */ public boolean isEnforceDestroyMethod() { return this.enforceDestroyMethod; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java index f98567a0707..5da53bfe3b6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @author Juergen Hoeller * @since 2.5 + * @see AbstractBeanDefinition#applyDefaults */ public class BeanDefinitionDefaults { @@ -46,6 +47,7 @@ public class BeanDefinitionDefaults { * Set whether beans should be lazily initialized by default. *

If {@code false}, the bean will get instantiated on startup by bean * factories that perform eager initialization of singletons. + * @see AbstractBeanDefinition#setLazyInit */ public void setLazyInit(boolean lazyInit) { this.lazyInit = lazyInit; @@ -78,6 +80,7 @@ public class BeanDefinitionDefaults { * (however, there may still be explicit annotation-driven autowiring). * @param autowireMode the autowire mode to set. * Must be one of the constants defined in {@link AbstractBeanDefinition}. + * @see AbstractBeanDefinition#setAutowireMode */ public void setAutowireMode(int autowireMode) { this.autowireMode = autowireMode; @@ -94,6 +97,7 @@ public class BeanDefinitionDefaults { * Set the dependency check code. * @param dependencyCheck the code to set. * Must be one of the constants defined in {@link AbstractBeanDefinition}. + * @see AbstractBeanDefinition#setDependencyCheck */ public void setDependencyCheck(int dependencyCheck) { this.dependencyCheck = dependencyCheck; @@ -108,6 +112,10 @@ public class BeanDefinitionDefaults { /** * Set the name of the default initializer method. + *

Note that this method is not enforced on all affected bean definitions + * but rather taken as an optional callback, to be invoked if actually present. + * @see AbstractBeanDefinition#setInitMethodName + * @see AbstractBeanDefinition#setEnforceInitMethod */ public void setInitMethodName(@Nullable String initMethodName) { this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null); @@ -123,6 +131,10 @@ public class BeanDefinitionDefaults { /** * Set the name of the default destroy method. + *

Note that this method is not enforced on all affected bean definitions + * but rather taken as an optional callback, to be invoked if actually present. + * @see AbstractBeanDefinition#setDestroyMethodName + * @see AbstractBeanDefinition#setEnforceDestroyMethod */ public void setDestroyMethodName(@Nullable String destroyMethodName) { this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null); From 01bab89dba66ad9300fc6396395eed2f87116ddc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Jul 2020 17:45:58 +0200 Subject: [PATCH 2/5] Consistently use PropertySource.getName() for comparison Includes synchronization for mutators on MutablePropertySources. Closes gh-25369 --- .../core/env/MutablePropertySources.java | 58 +++++++++++++------ .../core/env/PropertySource.java | 8 +-- .../support/WebApplicationContextUtils.java | 6 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java index 1fa383b38d9..1bc07bc7b54 100644 --- a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java +++ b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,14 +79,23 @@ public class MutablePropertySources implements PropertySources { @Override public boolean contains(String name) { - return this.propertySourceList.contains(PropertySource.named(name)); + for (PropertySource propertySource : this.propertySourceList) { + if (propertySource.getName().equals(name)) { + return true; + } + } + return false; } @Override @Nullable public PropertySource get(String name) { - int index = this.propertySourceList.indexOf(PropertySource.named(name)); - return (index != -1 ? this.propertySourceList.get(index) : null); + for (PropertySource propertySource : this.propertySourceList) { + if (propertySource.getName().equals(name)) { + return propertySource; + } + } + return null; } @@ -94,16 +103,20 @@ public class MutablePropertySources implements PropertySources { * Add the given property source object with highest precedence. */ public void addFirst(PropertySource propertySource) { - removeIfPresent(propertySource); - this.propertySourceList.add(0, propertySource); + synchronized (this.propertySourceList) { + removeIfPresent(propertySource); + this.propertySourceList.add(0, propertySource); + } } /** * Add the given property source object with lowest precedence. */ public void addLast(PropertySource propertySource) { - removeIfPresent(propertySource); - this.propertySourceList.add(propertySource); + synchronized (this.propertySourceList) { + removeIfPresent(propertySource); + this.propertySourceList.add(propertySource); + } } /** @@ -112,9 +125,11 @@ public class MutablePropertySources implements PropertySources { */ public void addBefore(String relativePropertySourceName, PropertySource propertySource) { assertLegalRelativeAddition(relativePropertySourceName, propertySource); - removeIfPresent(propertySource); - int index = assertPresentAndGetIndex(relativePropertySourceName); - addAtIndex(index, propertySource); + synchronized (this.propertySourceList) { + removeIfPresent(propertySource); + int index = assertPresentAndGetIndex(relativePropertySourceName); + addAtIndex(index, propertySource); + } } /** @@ -123,9 +138,11 @@ public class MutablePropertySources implements PropertySources { */ public void addAfter(String relativePropertySourceName, PropertySource propertySource) { assertLegalRelativeAddition(relativePropertySourceName, propertySource); - removeIfPresent(propertySource); - int index = assertPresentAndGetIndex(relativePropertySourceName); - addAtIndex(index + 1, propertySource); + synchronized (this.propertySourceList) { + removeIfPresent(propertySource); + int index = assertPresentAndGetIndex(relativePropertySourceName); + addAtIndex(index + 1, propertySource); + } } /** @@ -141,8 +158,10 @@ public class MutablePropertySources implements PropertySources { */ @Nullable public PropertySource remove(String name) { - int index = this.propertySourceList.indexOf(PropertySource.named(name)); - return (index != -1 ? this.propertySourceList.remove(index) : null); + synchronized (this.propertySourceList) { + int index = this.propertySourceList.indexOf(PropertySource.named(name)); + return (index != -1 ? this.propertySourceList.remove(index) : null); + } } /** @@ -153,8 +172,10 @@ public class MutablePropertySources implements PropertySources { * @see #contains */ public void replace(String name, PropertySource propertySource) { - int index = assertPresentAndGetIndex(name); - this.propertySourceList.set(index, propertySource); + synchronized (this.propertySourceList) { + int index = assertPresentAndGetIndex(name); + this.propertySourceList.set(index, propertySource); + } } /** @@ -169,6 +190,7 @@ public class MutablePropertySources implements PropertySources { return this.propertySourceList.toString(); } + /** * Ensure that the given property source is not being added relative to itself. */ diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java index c8a1da6bb82..24a71ddfadf 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java @@ -136,7 +136,7 @@ public abstract class PropertySource { @Override public boolean equals(@Nullable Object other) { return (this == other || (other instanceof PropertySource && - ObjectUtils.nullSafeEquals(this.name, ((PropertySource) other).name))); + ObjectUtils.nullSafeEquals(getName(), ((PropertySource) other).getName()))); } /** @@ -145,7 +145,7 @@ public abstract class PropertySource { */ @Override public int hashCode() { - return ObjectUtils.nullSafeHashCode(this.name); + return ObjectUtils.nullSafeHashCode(getName()); } /** @@ -161,10 +161,10 @@ public abstract class PropertySource { public String toString() { if (logger.isDebugEnabled()) { return getClass().getSimpleName() + "@" + System.identityHashCode(this) + - " {name='" + this.name + "', properties=" + this.source + "}"; + " {name='" + getName() + "', properties=" + getSource() + "}"; } else { - return getClass().getSimpleName() + " {name='" + this.name + "'}"; + return getClass().getSimpleName() + " {name='" + getName() + "'}"; } } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index 73da6c9e902..d9bfe57b152 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -296,11 +296,11 @@ public abstract class WebApplicationContextUtils { Assert.notNull(sources, "'propertySources' must not be null"); String name = StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME; - if (servletContext != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { + if (servletContext != null && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletContextPropertySource(name, servletContext)); } name = StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME; - if (servletConfig != null && sources.contains(name) && sources.get(name) instanceof StubPropertySource) { + if (servletConfig != null && sources.get(name) instanceof StubPropertySource) { sources.replace(name, new ServletConfigPropertySource(name, servletConfig)); } } From 30bf8708105db3bd49c4ee470165daaab98f3f4e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Jul 2020 17:47:53 +0200 Subject: [PATCH 3/5] Check JDBC 4 getFunctions (for compatibility with PostgreSQL driver 42.2.11) Closes gh-25399 --- .../metadata/GenericCallMetaDataProvider.java | 112 +++++++++++------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index 71983d28bcc..ef4ef9a8183 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,9 +46,8 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { /** Logger available to subclasses. */ protected static final Log logger = LogFactory.getLog(CallMetaDataProvider.class); - private boolean procedureColumnMetaDataUsed = false; - private String userName; + private final String userName; private boolean supportsCatalogsInProcedureCalls = true; @@ -58,7 +57,9 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { private boolean storesLowerCaseIdentifiers = false; - private List callParameterMetaData = new ArrayList<>(); + private boolean procedureColumnMetaDataUsed = false; + + private final List callParameterMetaData = new ArrayList<>(); /** @@ -328,20 +329,34 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { metaDataSchemaName + '/' + metaDataProcedureName); } - ResultSet procs = null; try { - procs = databaseMetaData.getProcedures(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName); List found = new ArrayList<>(); - while (procs.next()) { - found.add(procs.getString("PROCEDURE_CAT") + '.' + procs.getString("PROCEDURE_SCHEM") + - '.' + procs.getString("PROCEDURE_NAME")); + boolean function = false; + + try (ResultSet procedures = databaseMetaData.getProcedures( + metaDataCatalogName, metaDataSchemaName, metaDataProcedureName)) { + while (procedures.next()) { + found.add(procedures.getString("PROCEDURE_CAT") + '.' + procedures.getString("PROCEDURE_SCHEM") + + '.' + procedures.getString("PROCEDURE_NAME")); + } + } + + if (found.isEmpty()) { + // Functions not exposed as procedures anymore on PostgreSQL driver 42.2.11 + try (ResultSet functions = databaseMetaData.getFunctions( + metaDataCatalogName, metaDataSchemaName, metaDataProcedureName)) { + while (functions.next()) { + found.add(functions.getString("FUNCTION_CAT") + '.' + functions.getString("FUNCTION_SCHEM") + + '.' + functions.getString("FUNCTION_NAME")); + function = true; + } + } } - procs.close(); if (found.size() > 1) { throw new InvalidDataAccessApiUsageException( - "Unable to determine the correct call signature - multiple " + - "procedures/functions/signatures for '" + metaDataProcedureName + "': found " + found); + "Unable to determine the correct call signature - multiple signatures for '" + + metaDataProcedureName + "': found " + found + " " + (function ? "functions" : "procedures")); } else if (found.isEmpty()) { if (metaDataProcedureName != null && metaDataProcedureName.contains(".") && @@ -365,30 +380,34 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } } - procs = databaseMetaData.getProcedureColumns( - metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null); - while (procs.next()) { - String columnName = procs.getString("COLUMN_NAME"); - int columnType = procs.getInt("COLUMN_TYPE"); - if (columnName == null && ( - columnType == DatabaseMetaData.procedureColumnIn || - columnType == DatabaseMetaData.procedureColumnInOut || - columnType == DatabaseMetaData.procedureColumnOut)) { - if (logger.isDebugEnabled()) { - logger.debug("Skipping meta-data for: " + columnType + " " + procs.getInt("DATA_TYPE") + - " " + procs.getString("TYPE_NAME") + " " + procs.getInt("NULLABLE") + - " (probably a member of a collection)"); + if (logger.isDebugEnabled()) { + logger.debug("Retrieving column meta-data for " + (function ? "function" : "procedure") + ' ' + + metaDataCatalogName + '/' + metaDataSchemaName + '/' + metaDataProcedureName); + } + try (ResultSet columns = function ? + databaseMetaData.getFunctionColumns(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null) : + databaseMetaData.getProcedureColumns(metaDataCatalogName, metaDataSchemaName, metaDataProcedureName, null)) { + while (columns.next()) { + String columnName = columns.getString("COLUMN_NAME"); + int columnType = columns.getInt("COLUMN_TYPE"); + if (columnName == null && isInOrOutColumn(columnType, function)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping meta-data for: " + columnType + " " + columns.getInt("DATA_TYPE") + + " " + columns.getString("TYPE_NAME") + " " + columns.getInt("NULLABLE") + + " (probably a member of a collection)"); + } } - } - else { - CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType, - procs.getInt("DATA_TYPE"), procs.getString("TYPE_NAME"), - procs.getInt("NULLABLE") == DatabaseMetaData.procedureNullable); - this.callParameterMetaData.add(meta); - if (logger.isDebugEnabled()) { - logger.debug("Retrieved meta-data: " + meta.getParameterName() + " " + - meta.getParameterType() + " " + meta.getSqlType() + " " + - meta.getTypeName() + " " + meta.isNullable()); + else { + int nullable = (function ? DatabaseMetaData.functionNullable : DatabaseMetaData.procedureNullable); + CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType, + columns.getInt("DATA_TYPE"), columns.getString("TYPE_NAME"), + columns.getInt("NULLABLE") == nullable); + this.callParameterMetaData.add(meta); + if (logger.isDebugEnabled()) { + logger.debug("Retrieved meta-data: " + meta.getParameterName() + " " + + meta.getParameterType() + " " + meta.getSqlType() + " " + + meta.getTypeName() + " " + meta.isNullable()); + } } } } @@ -398,17 +417,18 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { logger.warn("Error while retrieving meta-data for procedure columns: " + ex); } } - finally { - try { - if (procs != null) { - procs.close(); - } - } - catch (SQLException ex) { - if (logger.isWarnEnabled()) { - logger.warn("Problem closing ResultSet for procedure column meta-data: " + ex); - } - } + } + + private static boolean isInOrOutColumn(int columnType, boolean function) { + if (function) { + return (columnType == DatabaseMetaData.functionColumnIn || + columnType == DatabaseMetaData.functionColumnInOut || + columnType == DatabaseMetaData.functionColumnOut); + } + else { + return (columnType == DatabaseMetaData.procedureColumnIn || + columnType == DatabaseMetaData.procedureColumnInOut || + columnType == DatabaseMetaData.procedureColumnOut); } } From e9898f7d5217360afe23b6f03ee4226ad136d4d1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Jul 2020 17:48:33 +0200 Subject: [PATCH 4/5] Polishing --- ...tractJndiLocatingBeanDefinitionParser.java | 7 +++--- .../ejb/config/JeeNamespaceHandlerTests.java | 24 ++++++++++--------- .../web/bind/annotation/RequestMapping.java | 3 +-- .../web/reactive/config/CorsRegistration.java | 11 +++++---- .../web/reactive/config/CorsRegistry.java | 8 ++++--- .../annotation/ControllerMethodResolver.java | 4 ++-- ...equestAttributeMethodArgumentResolver.java | 3 +-- .../config/annotation/CorsRegistration.java | 12 +++++----- .../config/annotation/CorsRegistry.java | 2 -- .../RequestMappingHandlerAdapter.java | 8 +++---- 10 files changed, 42 insertions(+), 40 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/ejb/config/AbstractJndiLocatingBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/ejb/config/AbstractJndiLocatingBeanDefinitionParser.java index 51e9a3fff95..34c4ac5c9ad 100644 --- a/spring-context/src/main/java/org/springframework/ejb/config/AbstractJndiLocatingBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/ejb/config/AbstractJndiLocatingBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,9 @@ abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBe @Override protected boolean isEligibleAttribute(String attributeName) { - return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName) && !LAZY_INIT_ATTRIBUTE - .equals(attributeName)); + return (super.isEligibleAttribute(attributeName) && + !ENVIRONMENT_REF.equals(attributeName) && + !LAZY_INIT_ATTRIBUTE.equals(attributeName)); } @Override diff --git a/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java index 2b4ac0d08c0..ec9662810e6 100644 --- a/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/ejb/config/JeeNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,9 @@ public class JeeNamespaceHandlerTests { private ConfigurableListableBeanFactory beanFactory; + @BeforeEach - public void setUp() throws Exception { + public void setup() { GenericApplicationContext ctx = new GenericApplicationContext(); new XmlBeanDefinitionReader(ctx).loadBeanDefinitions( new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass())); @@ -52,8 +53,9 @@ public class JeeNamespaceHandlerTests { this.beanFactory.getBeanNamesForType(ITestBean.class); } + @Test - public void testSimpleDefinition() throws Exception { + public void testSimpleDefinition() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simple"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource"); @@ -61,7 +63,7 @@ public class JeeNamespaceHandlerTests { } @Test - public void testComplexDefinition() throws Exception { + public void testComplexDefinition() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complex"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(JndiObjectFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource"); @@ -75,21 +77,21 @@ public class JeeNamespaceHandlerTests { } @Test - public void testWithEnvironment() throws Exception { + public void testWithEnvironment() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withEnvironment"); assertPropertyValue(beanDefinition, "jndiEnvironment", "foo=bar"); assertPropertyValue(beanDefinition, "defaultObject", new RuntimeBeanReference("myBean")); } @Test - public void testWithReferencedEnvironment() throws Exception { + public void testWithReferencedEnvironment() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("withReferencedEnvironment"); assertPropertyValue(beanDefinition, "jndiEnvironment", new RuntimeBeanReference("myEnvironment")); assertThat(beanDefinition.getPropertyValues().contains("environmentRef")).isFalse(); } @Test - public void testSimpleLocalSlsb() throws Exception { + public void testSimpleLocalSlsb() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleLocalEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); @@ -97,7 +99,7 @@ public class JeeNamespaceHandlerTests { } @Test - public void testSimpleRemoteSlsb() throws Exception { + public void testSimpleRemoteSlsb() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simpleRemoteEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); @@ -105,7 +107,7 @@ public class JeeNamespaceHandlerTests { } @Test - public void testComplexLocalSlsb() throws Exception { + public void testComplexLocalSlsb() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexLocalEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(LocalStatelessSessionProxyFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); @@ -117,7 +119,7 @@ public class JeeNamespaceHandlerTests { } @Test - public void testComplexRemoteSlsb() throws Exception { + public void testComplexRemoteSlsb() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complexRemoteEjb"); assertThat(beanDefinition.getBeanClassName()).isEqualTo(SimpleRemoteStatelessSessionProxyFactoryBean.class.getName()); assertPropertyValue(beanDefinition, "businessInterface", ITestBean.class.getName()); @@ -132,7 +134,7 @@ public class JeeNamespaceHandlerTests { } @Test - public void testLazyInitJndiLookup() throws Exception { + public void testLazyInitJndiLookup() { BeanDefinition definition = this.beanFactory.getMergedBeanDefinition("lazyDataSource"); assertThat(definition.isLazyInit()).isTrue(); definition = this.beanFactory.getMergedBeanDefinition("lazyLocalBean"); diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java index f54a8db1f23..a0e357e8f86 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java @@ -202,7 +202,7 @@ public @interface RequestMapping { * produces = "text/plain;charset=UTF-8" * *

If a declared media type contains a parameter (e.g. "charset=UTF-8", - * "type=feed", type="entry") and if a compatible media type from the request + * "type=feed", "type=entry") and if a compatible media type from the request * has that parameter too, then the parameter values must match. Otherwise * if the media type from the request does not contain the parameter, it is * assumed the client accepts any value. @@ -212,7 +212,6 @@ public @interface RequestMapping { * If specified at both levels, the method level produces condition overrides * the type level condition. * @see org.springframework.http.MediaType - * @see org.springframework.http.MediaType */ String[] produces() default {}; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistration.java index 8dad2ae07fc..096935e79da 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistration.java @@ -16,7 +16,6 @@ package org.springframework.web.reactive.config; -import java.util.ArrayList; import java.util.Arrays; import org.springframework.web.cors.CorsConfiguration; @@ -28,6 +27,7 @@ import org.springframework.web.cors.CorsConfiguration; * @author Sebastien Deleuze * @author Rossen Stoyanchev * @since 5.0 + * @see CorsConfiguration * @see CorsRegistry */ public class CorsRegistration { @@ -39,6 +39,7 @@ public class CorsRegistration { public CorsRegistration(String pathPattern) { this.pathPattern = pathPattern; + // Same implicit default values as the @CrossOrigin annotation + allows simple methods this.config = new CorsConfiguration().applyPermitDefaultValues(); } @@ -58,7 +59,7 @@ public class CorsRegistration { * See the Spring Framework reference for more on this filter. */ public CorsRegistration allowedOrigins(String... origins) { - this.config.setAllowedOrigins(new ArrayList<>(Arrays.asList(origins))); + this.config.setAllowedOrigins(Arrays.asList(origins)); return this; } @@ -69,7 +70,7 @@ public class CorsRegistration { * are allowed. */ public CorsRegistration allowedMethods(String... methods) { - this.config.setAllowedMethods(new ArrayList<>(Arrays.asList(methods))); + this.config.setAllowedMethods(Arrays.asList(methods)); return this; } @@ -83,7 +84,7 @@ public class CorsRegistration { *

By default all headers are allowed. */ public CorsRegistration allowedHeaders(String... headers) { - this.config.setAllowedHeaders(new ArrayList<>(Arrays.asList(headers))); + this.config.setAllowedHeaders(Arrays.asList(headers)); return this; } @@ -96,7 +97,7 @@ public class CorsRegistration { *

By default this is not set. */ public CorsRegistration exposedHeaders(String... headers) { - this.config.setExposedHeaders(new ArrayList<>(Arrays.asList(headers))); + this.config.setExposedHeaders(Arrays.asList(headers)); return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistry.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistry.java index b0b817d2693..263e66c15ee 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistry.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistry.java @@ -37,11 +37,9 @@ public class CorsRegistry { /** - * Enable cross origin request handling for the specified path pattern. - * + * Enable cross-origin request handling for the specified path pattern. *

Exact path mapping URIs (such as {@code "/admin"}) are supported as * well as Ant-style path patterns (such as {@code "/admin/**"}). - * *

By default, the {@code CorsConfiguration} for this mapping is * initialized with default values as described in * {@link CorsConfiguration#applyPermitDefaultValues()}. @@ -52,6 +50,10 @@ public class CorsRegistry { return registration; } + /** + * Return the registered {@link CorsConfiguration} objects, + * keyed by path pattern. + */ protected Map getCorsConfigurations() { Map configs = new LinkedHashMap<>(this.registrations.size()); for (CorsRegistration registration : this.registrations) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java index 961b922074a..7063267742d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -169,7 +169,7 @@ class ControllerMethodResolver { boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding; // Annotation-based... - List result = new ArrayList<>(); + List result = new ArrayList<>(30); result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false)); result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry)); result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry)); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java index a8f656d1aa4..627538a4a61 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,6 @@ import org.springframework.web.server.ServerWebInputException; */ public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver { - /** * Create a new {@link RequestAttributeMethodArgumentResolver} instance. * @param factory a bean factory to use for resolving {@code ${...}} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java index cf641d3218f..a7bb9371abc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java @@ -67,9 +67,9 @@ public class CorsRegistration { /** * Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"}, etc. - * The special value {@code "*"} allows all methods. - *

By default "simple" methods, i.e. {@code GET}, {@code HEAD}, and - * {@code POST} are allowed. + *

The special value {@code "*"} allows all methods. + *

By default "simple" methods {@code GET}, {@code HEAD}, and {@code POST} + * are allowed. */ public CorsRegistration allowedMethods(String... methods) { this.config.setAllowedMethods(Arrays.asList(methods)); @@ -77,9 +77,9 @@ public class CorsRegistration { } /** - * Set the list of headers that a preflight request can list as allowed - * for use during an actual request. The special value {@code "*"} may be - * used to allow all headers. + * Set the list of headers that a pre-flight request can list as allowed + * for use during an actual request. + *

The special value {@code "*"} may be used to allow all headers. *

A header name is not required to be listed if it is one of: * {@code Cache-Control}, {@code Content-Language}, {@code Expires}, * {@code Last-Modified}, or {@code Pragma} as per the CORS spec. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java index da4c1493ad8..ad93c973ac9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java @@ -39,10 +39,8 @@ public class CorsRegistry { /** * Enable cross-origin request handling for the specified path pattern. - * *

Exact path mapping URIs (such as {@code "/admin"}) are supported as * well as Ant-style path patterns (such as {@code "/admin/**"}). - * *

By default, the {@code CorsConfiguration} for this mapping is * initialized with default values as described in * {@link CorsConfiguration#applyPermitDefaultValues()}. 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 66049d310e0..a3b09fa17c3 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 @@ -151,7 +151,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter private List> messageConverters; - private List requestResponseBodyAdvice = new ArrayList<>(); + private final List requestResponseBodyAdvice = new ArrayList<>(); @Nullable private WebBindingInitializer webBindingInitializer; @@ -632,7 +632,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * and custom resolvers provided via {@link #setCustomArgumentResolvers}. */ private List getDefaultArgumentResolvers() { - List resolvers = new ArrayList<>(); + List resolvers = new ArrayList<>(30); // Annotation-based argument resolution resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); @@ -679,7 +679,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * methods including built-in and custom resolvers. */ private List getDefaultInitBinderArgumentResolvers() { - List resolvers = new ArrayList<>(); + List resolvers = new ArrayList<>(20); // Annotation-based argument resolution resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); @@ -712,7 +712,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * custom handlers provided via {@link #setReturnValueHandlers}. */ private List getDefaultReturnValueHandlers() { - List handlers = new ArrayList<>(); + List handlers = new ArrayList<>(20); // Single-purpose return value types handlers.add(new ModelAndViewMethodReturnValueHandler()); From 851908851d2d4adeee2112bc58625d59fe516788 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 17 Jul 2020 17:49:24 +0200 Subject: [PATCH 5/5] Upgrade to Tomcat 9.0.37, Netty 4.1.51, Apache Johnzon 1.2.8, OpenPDF 1.3.20, Caffeine 2.8.5, Hessian 4.0.63 --- build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 3afbe10402c..b1b650f1d2c 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ configure(allprojects) { project -> dependencyManagement { imports { mavenBom "com.fasterxml.jackson:jackson-bom:2.10.4" - mavenBom "io.netty:netty-bom:4.1.50.Final" + mavenBom "io.netty:netty-bom:4.1.51.Final" mavenBom "io.projectreactor:reactor-bom:Dysprosium-BUILD-SNAPSHOT" mavenBom "io.rsocket:rsocket-bom:1.0.1" mavenBom "org.eclipse.jetty:jetty-bom:9.4.30.v20200611" @@ -63,7 +63,7 @@ configure(allprojects) { project -> dependency "io.reactivex.rxjava2:rxjava:2.2.19" dependency "io.projectreactor.tools:blockhound:1.0.2.RELEASE" - dependency "com.caucho:hessian:4.0.62" + dependency "com.caucho:hessian:4.0.63" dependency "com.fasterxml:aalto-xml:1.2.2" dependency("com.fasterxml.woodstox:woodstox-core:6.1.1") { exclude group: "stax", name: "stax-api" @@ -75,7 +75,7 @@ configure(allprojects) { project -> exclude group: "xpp3", name: "xpp3_min" exclude group: "xmlpull", name: "xmlpull" } - dependency "org.apache.johnzon:johnzon-jsonb:1.2.7" + dependency "org.apache.johnzon:johnzon-jsonb:1.2.8" dependency("org.codehaus.jettison:jettison:1.3.8") { exclude group: "stax", name: "stax-api" } @@ -87,8 +87,8 @@ configure(allprojects) { project -> dependency "org.yaml:snakeyaml:1.26" dependency "com.h2database:h2:1.4.200" - dependency "com.github.ben-manes.caffeine:caffeine:2.8.4" - dependency "com.github.librepdf:openpdf:1.3.19" + dependency "com.github.ben-manes.caffeine:caffeine:2.8.5" + dependency "com.github.librepdf:openpdf:1.3.20" dependency "com.rometools:rome:1.12.2" dependency "commons-io:commons-io:2.5" dependency "io.vavr:vavr:0.10.3" @@ -120,14 +120,14 @@ configure(allprojects) { project -> dependency "org.webjars:webjars-locator-core:0.45" dependency "org.webjars:underscorejs:1.8.3" - dependencySet(group: 'org.apache.tomcat', version: '9.0.36') { + dependencySet(group: 'org.apache.tomcat', version: '9.0.37') { entry 'tomcat-util' entry('tomcat-websocket') { exclude group: "org.apache.tomcat", name: "tomcat-websocket-api" exclude group: "org.apache.tomcat", name: "tomcat-servlet-api" } } - dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.36') { + dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.37') { entry 'tomcat-embed-core' entry 'tomcat-embed-websocket' }