From 5bb1c3e1e31772a30a7fdef74e60f39a6bb65f29 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Mon, 11 Feb 2019 13:18:28 +0100 Subject: [PATCH 1/3] Deprecate SqlXmlObjectMappingHandler This class is only known to be used in spring-data-jdbc-ext project which was never upgraded to Spring Framework 5.x and is no longer actively developed. Closes gh-11647 --- .../jdbc/support/xml/SqlXmlObjectMappingHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java index 1f8d4f7418..d0483fbda3 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/SqlXmlObjectMappingHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -32,7 +32,10 @@ import org.springframework.lang.Nullable; * @since 2.5.5 * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML + * @deprecated as of Spring Framework 5.1.5 since this class is only known to be used in spring-data-jdbc-ext project + * which was never upgraded to Spring Framework 5.x and is no longer actively developed */ +@Deprecated public interface SqlXmlObjectMappingHandler extends SqlXmlHandler { /** From 8637540678637c306d38f0681b8c057c791c5c94 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Feb 2019 09:07:51 +0100 Subject: [PATCH 2/3] Expose empty annotation array as empty AnnotationAttributes array Closes gh-22405 --- .../ConfigurationClassPostProcessorTests.java | 25 ++++++++++++++++++- .../RecursiveAnnotationArrayVisitor.java | 8 ++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java index b8daeec4de..1b197f4ac3 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.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. @@ -184,6 +184,20 @@ public class ConfigurationClassPostProcessorTests { assertSupportForComposedAnnotationWithExclude(beanDefinition); } + @Test + public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingReflection() { + RootBeanDefinition beanDefinition = new RootBeanDefinition( + ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class); + assertSupportForComposedAnnotationWithExclude(beanDefinition); + } + + @Test + public void postProcessorWorksWithExtendedConfigurationWithAttributeOverrideForExcludesFilterUsingAsm() { + RootBeanDefinition beanDefinition = new RootBeanDefinition( + ExtendedConfigurationWithAttributeOverrideForExcludeFilter.class.getName()); + assertSupportForComposedAnnotationWithExclude(beanDefinition); + } + @Test public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingReflection() { RootBeanDefinition beanDefinition = new RootBeanDefinition( @@ -1515,6 +1529,15 @@ public class ConfigurationClassPostProcessorTests { public static class ComposedConfigurationWithAttributeOverrideForExcludeFilter { } + @ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.base", excludeFilters = {}) + public static class BaseConfigurationWithEmptyExcludeFilters { + } + + @ComponentScan(basePackages = "org.springframework.context.annotation.componentscan.simple", + excludeFilters = @ComponentScan.Filter(Component.class)) + public static class ExtendedConfigurationWithAttributeOverrideForExcludeFilter extends BaseConfigurationWithEmptyExcludeFilters { + } + @ComposedConfigurationWithAttributeOverrides @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java index a4530bb79b..3e5bcff04a 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/RecursiveAnnotationArrayVisitor.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. @@ -89,7 +89,11 @@ class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationVisitor try { Class attributeType = annotationType.getMethod(this.attributeName).getReturnType(); if (attributeType.isArray()) { - this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0)); + Class elementType = attributeType.getComponentType(); + if (elementType.isAnnotation()) { + elementType = AnnotationAttributes.class; + } + this.attributes.put(this.attributeName, Array.newInstance(elementType, 0)); } } catch (NoSuchMethodException ex) { From 106a7570981b83af3bf4855207e290de5fc30718 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 12 Feb 2019 09:07:58 +0100 Subject: [PATCH 3/3] Polishing --- .../core/annotation/AnnotationAttributes.java | 4 ++-- .../type/classreading/AnnotationReadingVisitorUtils.java | 5 +++-- .../core/annotation/AnnotationAttributesTests.java | 4 ++-- .../init/test-data-with-multi-line-nested-comments.sql | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java index 9fc70e72a8..577a17e349 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.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. @@ -363,7 +363,7 @@ public class AnnotationAttributes extends LinkedHashMap { private void assertAttributeType(String attributeName, Object attributeValue, Class expectedType) { if (!expectedType.isInstance(attributeValue)) { throw new IllegalArgumentException(String.format( - "Attribute '%s' is of type [%s], but [%s] was expected in attributes for annotation [%s]", + "Attribute '%s' is of type %s, but %s was expected in attributes for annotation [%s]", attributeName, attributeValue.getClass().getSimpleName(), expectedType.getSimpleName(), this.displayName)); } diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java index f4084cd818..7ecf7d80fa 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.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. @@ -28,6 +28,7 @@ import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.ObjectUtils; @@ -124,7 +125,7 @@ abstract class AnnotationReadingVisitorUtils { // Get the unmerged list of attributes for the target annotation. List attributesList = attributesMap.get(annotationName); - if (attributesList == null || attributesList.isEmpty()) { + if (CollectionUtils.isEmpty(attributesList)) { return null; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java index 5908bf3693..8baea8d2e9 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationAttributesTests.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. @@ -154,7 +154,7 @@ public class AnnotationAttributesTests { public void getEnumWithTypeMismatch() { attributes.put("color", "RED"); exception.expect(IllegalArgumentException.class); - exception.expectMessage(containsString("Attribute 'color' is of type [String], but [Enum] was expected")); + exception.expectMessage(containsString("Attribute 'color' is of type String, but Enum was expected")); attributes.getEnum("color"); } diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/test-data-with-multi-line-nested-comments.sql b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/test-data-with-multi-line-nested-comments.sql index 8c1e1174b7..7faa91c250 100644 --- a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/test-data-with-multi-line-nested-comments.sql +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/test-data-with-multi-line-nested-comments.sql @@ -11,7 +11,7 @@ INSERT INTO users(first_name, last_name) VALUES('Juergen', 'Hoeller'); -- A fancy multi-line comments that puts -- single line comments inside of a multi-line -- comment block. -Moreover, the block commend end delimiter +Moreover, the block comment end delimiter appears on a line that can potentially also be a single-line comment if we weren't already inside a multi-line comment run.