diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index b4abf0f4d8..5afc4a2607 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -247,7 +247,8 @@ class ConfigurationClassBeanDefinitionReader { BeanDefinition beanDefToRegister = beanDef; if (proxyMode != ScopedProxyMode.NO) { BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy( - new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS); + new BeanDefinitionHolder(beanDef, beanName), this.registry, + proxyMode == ScopedProxyMode.TARGET_CLASS); beanDefToRegister = new ConfigurationClassBeanDefinition( (RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata); } @@ -272,7 +273,8 @@ class ConfigurationClassBeanDefinitionReader { // preserve the existing bean definition. if (existingBeanDef instanceof ConfigurationClassBeanDefinition) { ConfigurationClassBeanDefinition ccbd = (ConfigurationClassBeanDefinition) existingBeanDef; - return (ccbd.getMetadata().getClassName().equals(beanMethod.getConfigurationClass().getMetadata().getClassName())); + return ccbd.getMetadata().getClassName().equals( + beanMethod.getConfigurationClass().getMetadata().getClassName()); } // A bean definition resulting from a component scan can be silently overridden diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index a4faae3297..d10fb2bb29 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -231,7 +231,7 @@ class ConfigurationClassParser { // Explicit bean definition found, probably replacing an import. // Let's remove the old one and go with the new one. this.configurationClasses.remove(configClass); - for (Iterator it = this.knownSuperclasses.values().iterator(); it.hasNext(); ) { + for (Iterator it = this.knownSuperclasses.values().iterator(); it.hasNext();) { if (configClass.equals(it.next())) { it.remove(); } @@ -257,13 +257,16 @@ class ConfigurationClassParser { * @param sourceClass a source class * @return the superclass, or {@code null} if none found or previously processed */ - protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { + protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) + throws IOException { + // Recursively process any member (nested) classes first processMemberClasses(configClass, sourceClass); // Process any @PropertySource annotations for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable( - sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) { + sourceClass.getMetadata(), PropertySources.class, + org.springframework.context.annotation.PropertySource.class)) { if (this.environment instanceof ConfigurableEnvironment) { processPropertySource(propertySource); } @@ -276,14 +279,16 @@ class ConfigurationClassParser { // Process any @ComponentScan annotations Set componentScans = AnnotationConfigUtils.attributesForRepeatable( sourceClass.getMetadata(), ComponentScans.class, ComponentScan.class); - if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) { + if (!componentScans.isEmpty() && + !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) { for (AnnotationAttributes componentScan : componentScans) { // The config class is annotated with @ComponentScan -> perform the scan immediately Set scannedBeanDefinitions = this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName()); - // Check the set of scanned definitions for any further config classes and parse recursively if necessary + // Check the set of scanned definitions for any further config classes and parse recursively if needed for (BeanDefinitionHolder holder : scannedBeanDefinitions) { - if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) { + if (ConfigurationClassUtils.checkConfigurationClassCandidate( + holder.getBeanDefinition(), this.metadataReaderFactory)) { parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName()); } } @@ -517,7 +522,9 @@ class ConfigurationClassParser { * @param visited used to track visited classes to prevent infinite recursion * @throws IOException if there is any problem reading metadata from the named class */ - private void collectImports(SourceClass sourceClass, Set imports, Set visited) throws IOException { + private void collectImports(SourceClass sourceClass, Set imports, Set visited) + throws IOException { + if (visited.add(sourceClass)) { for (SourceClass annotation : sourceClass.getAnnotations()) { String annName = annotation.getMetadata().getClassName(); @@ -544,7 +551,8 @@ class ConfigurationClassParser { throw ex; } catch (Throwable ex) { - throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" + + throw new BeanDefinitionStoreException( + "Failed to process import candidates for configuration class [" + configClass.getMetadata().getClassName() + "]", ex); } } @@ -603,7 +611,8 @@ class ConfigurationClassParser { throw ex; } catch (Throwable ex) { - throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" + + throw new BeanDefinitionStoreException( + "Failed to process import candidates for configuration class [" + configClass.getMetadata().getClassName() + "]", ex); } finally { @@ -742,9 +751,9 @@ class ConfigurationClassParser { private final DeferredImportSelector importSelector; - public DeferredImportSelectorHolder(ConfigurationClass configurationClass, DeferredImportSelector importSelector) { - this.configurationClass = configurationClass; - this.importSelector = importSelector; + public DeferredImportSelectorHolder(ConfigurationClass configClass, DeferredImportSelector selector) { + this.configurationClass = configClass; + this.importSelector = selector; } public ConfigurationClass getConfigurationClass() { @@ -878,8 +887,8 @@ class ConfigurationClassParser { return result; } - public Collection getAnnotationAttributes(String annotationType, String attribute) throws IOException { - Map annotationAttributes = this.metadata.getAnnotationAttributes(annotationType, true); + public Collection getAnnotationAttributes(String annType, String attribute) throws IOException { + Map annotationAttributes = this.metadata.getAnnotationAttributes(annType, true); if (annotationAttributes == null || !annotationAttributes.containsKey(attribute)) { return Collections.emptySet(); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index 53ca8273c8..c019c61d52 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -287,11 +287,11 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo }); // Detect any custom bean name generation strategy supplied through the enclosing application context - SingletonBeanRegistry singletonRegistry = null; + SingletonBeanRegistry sbr = null; if (registry instanceof SingletonBeanRegistry) { - singletonRegistry = (SingletonBeanRegistry) registry; - if (!this.localBeanNameGeneratorSet && singletonRegistry.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) { - BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR); + sbr = (SingletonBeanRegistry) registry; + if (!this.localBeanNameGeneratorSet && sbr.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) { + BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR); this.componentScanBeanNameGenerator = generator; this.importBeanNameGenerator = generator; } @@ -330,10 +330,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } for (String candidateName : newCandidateNames) { if (!oldCandidateNames.contains(candidateName)) { - BeanDefinition beanDef = registry.getBeanDefinition(candidateName); - if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory) && - !alreadyParsedClasses.contains(beanDef.getBeanClassName())) { - candidates.add(new BeanDefinitionHolder(beanDef, candidateName)); + BeanDefinition bd = registry.getBeanDefinition(candidateName); + if (ConfigurationClassUtils.checkConfigurationClassCandidate(bd, this.metadataReaderFactory) && + !alreadyParsedClasses.contains(bd.getBeanClassName())) { + candidates.add(new BeanDefinitionHolder(bd, candidateName)); } } } @@ -343,9 +343,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo while (!candidates.isEmpty()); // Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes - if (singletonRegistry != null) { - if (!singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) { - singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry()); + if (sbr != null) { + if (!sbr.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) { + sbr.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry()); } } @@ -415,7 +415,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } @Override - public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) { + public PropertyValues postProcessPropertyValues( + PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) { + // Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's // postProcessPropertyValues method attempts to autowire other configuration beans. if (bean instanceof EnhancedConfiguration) { @@ -427,8 +429,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo @Override public Object postProcessBeforeInitialization(Object bean, String beanName) { if (bean instanceof ImportAware) { - ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); - AnnotationMetadata importingClass = importRegistry.getImportingClassFor(bean.getClass().getSuperclass().getName()); + ImportRegistry ir = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class); + AnnotationMetadata importingClass = ir.getImportingClassFor(bean.getClass().getSuperclass().getName()); if (importingClass != null) { ((ImportAware) bean).setImportMetadata(importingClass); } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index 8d997271bd..f887ee70bb 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -270,9 +270,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class[] {String.class, int.class}); NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy(); - proxy = (NoArgCtorTestBean) aop.getProxy(); - - assertNotNull("Proxy should be null", proxy); + assertNotNull(proxy); } @Test diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index c5ba7ba2ee..5e98f9b723 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -1078,10 +1078,10 @@ public abstract class ClassUtils { } /** - * Return all interfaces that the given instance implements as array, + * Return all interfaces that the given instance implements as an array, * including ones implemented by superclasses. * @param instance the instance to analyze for interfaces - * @return all interfaces that the given instance implements as array + * @return all interfaces that the given instance implements as an array */ public static Class[] getAllInterfaces(Object instance) { Assert.notNull(instance, "Instance must not be null"); @@ -1089,24 +1089,24 @@ public abstract class ClassUtils { } /** - * Return all interfaces that the given class implements as array, + * Return all interfaces that the given class implements as an array, * including ones implemented by superclasses. *

If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces - * @return all interfaces that the given object implements as array + * @return all interfaces that the given object implements as an array */ public static Class[] getAllInterfacesForClass(Class clazz) { return getAllInterfacesForClass(clazz, null); } /** - * Return all interfaces that the given class implements as array, + * Return all interfaces that the given class implements as an array, * including ones implemented by superclasses. *

If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be {@code null} when accepting all declared interfaces) - * @return all interfaces that the given object implements as array + * @return all interfaces that the given object implements as an array */ public static Class[] getAllInterfacesForClass(Class clazz, ClassLoader classLoader) { Set> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader); @@ -1114,10 +1114,10 @@ public abstract class ClassUtils { } /** - * Return all interfaces that the given instance implements as Set, + * Return all interfaces that the given instance implements as a Set, * including ones implemented by superclasses. * @param instance the instance to analyze for interfaces - * @return all interfaces that the given instance implements as Set + * @return all interfaces that the given instance implements as a Set */ public static Set> getAllInterfacesAsSet(Object instance) { Assert.notNull(instance, "Instance must not be null"); @@ -1125,24 +1125,24 @@ public abstract class ClassUtils { } /** - * Return all interfaces that the given class implements as Set, + * Return all interfaces that the given class implements as a Set, * including ones implemented by superclasses. *

If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces - * @return all interfaces that the given object implements as Set + * @return all interfaces that the given object implements as a Set */ public static Set> getAllInterfacesForClassAsSet(Class clazz) { return getAllInterfacesForClassAsSet(clazz, null); } /** - * Return all interfaces that the given class implements as Set, + * Return all interfaces that the given class implements as a Set, * including ones implemented by superclasses. *

If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyze for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be {@code null} when accepting all declared interfaces) - * @return all interfaces that the given object implements as Set + * @return all interfaces that the given object implements as a Set */ public static Set> getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); diff --git a/spring-jms/src/main/java/org/springframework/jms/support/JmsHeaders.java b/spring-jms/src/main/java/org/springframework/jms/support/JmsHeaders.java index 3c97d06e42..c40459eec7 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/JmsHeaders.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/JmsHeaders.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -31,7 +31,7 @@ public interface JmsHeaders { * user-defined headers and other internal headers (e.g. correlationId). * @see SimpleJmsHeaderMapper */ - public static final String PREFIX = "jms_"; + String PREFIX = "jms_"; /** * Correlation ID for the message. This may be the {@link #MESSAGE_ID} of @@ -39,7 +39,7 @@ public interface JmsHeaders { * application-specific identifier. * @see javax.jms.Message#getJMSCorrelationID() */ - public static final String CORRELATION_ID = PREFIX + "correlationId"; + String CORRELATION_ID = PREFIX + "correlationId"; /** * Name of the destination (topic or queue) of the message. @@ -49,7 +49,7 @@ public interface JmsHeaders { * @see javax.jms.Queue * @see javax.jms.Topic */ - public static final String DESTINATION = PREFIX + "destination"; + String DESTINATION = PREFIX + "destination"; /** * Distribution mode. @@ -57,35 +57,35 @@ public interface JmsHeaders { * @see javax.jms.Message#getJMSDeliveryMode() * @see javax.jms.DeliveryMode */ - public static final String DELIVERY_MODE = PREFIX + "deliveryMode"; + String DELIVERY_MODE = PREFIX + "deliveryMode"; /** * Message expiration date and time. *

Read-only value. * @see javax.jms.Message#getJMSExpiration() */ - public static final String EXPIRATION = PREFIX + "expiration"; + String EXPIRATION = PREFIX + "expiration"; /** - * Unique Identifier for a message. + * Unique identifier for a message. *

Read-only value. * @see javax.jms.Message#getJMSMessageID() */ - public static final String MESSAGE_ID = PREFIX + "messageId"; + String MESSAGE_ID = PREFIX + "messageId"; /** * The message priority level. *

Read-only value. * @see javax.jms.Message#getJMSPriority() */ - public static final String PRIORITY = PREFIX + "priority"; + String PRIORITY = PREFIX + "priority"; /** * Name of the destination (topic or queue) the message replies should * be sent to. * @see javax.jms.Message#getJMSReplyTo() */ - public static final String REPLY_TO = PREFIX + "replyTo"; + String REPLY_TO = PREFIX + "replyTo"; /** * Specify if the message was resent. This occurs when a message @@ -93,20 +93,20 @@ public interface JmsHeaders { *

Read-only value. * @see javax.jms.Message#getJMSRedelivered() */ - public static final String REDELIVERED = PREFIX + "redelivered"; + String REDELIVERED = PREFIX + "redelivered"; /** * Message type label. This type is a string value describing the message * in a functional manner. * @see javax.jms.Message#getJMSType() */ - public static final String TYPE = PREFIX + "type"; + String TYPE = PREFIX + "type"; /** * Date and time of the message sending operation. *

Read-only value. * @see javax.jms.Message#getJMSTimestamp() */ - public static final String TIMESTAMP = PREFIX + "timestamp"; + String TIMESTAMP = PREFIX + "timestamp"; }