diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java index 32d9d93f5d..70b8998ba5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java @@ -48,7 +48,7 @@ abstract class PropertyDescriptorUtils { * @param beanClass the target class to introspect * @return a collection of property descriptors * @throws IntrospectionException from introspecting the given bean class - * @since 6.0 + * @since 5.3.24 * @see SimpleBeanInfoFactory * @see java.beans.Introspector#getBeanInfo(Class) */ @@ -57,6 +57,7 @@ abstract class PropertyDescriptorUtils { for (Method method : beanClass.getMethods()) { String methodName = method.getName(); + boolean setter; int nameIndex; if (methodName.startsWith("set") && method.getParameterCount() == 1) { @@ -76,6 +77,10 @@ abstract class PropertyDescriptorUtils { } String propertyName = StringUtils.uncapitalizeAsProperty(methodName.substring(nameIndex)); + if (propertyName.isEmpty()) { + continue; + } + PropertyDescriptor pd = pdMap.get(propertyName); if (pd != null) { if (setter) { @@ -262,6 +267,7 @@ abstract class PropertyDescriptorUtils { * PropertyDescriptor for {@link #determineBasicProperties(Class)}, * not performing any early type determination for * {@link #setReadMethod}/{@link #setWriteMethod}. + * @since 5.3.24 */ private static class BasicPropertyDescriptor extends PropertyDescriptor { diff --git a/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java b/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java index c2835bc797..99a53aada5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java @@ -39,7 +39,7 @@ import org.springframework.lang.NonNull; * {@link BeanInfoFactory} types to take precedence. * * @author Juergen Hoeller - * @since 6.0 + * @since 5.3.24 * @see ExtendedBeanInfoFactory * @see CachedIntrospectionResults */ 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 47e339331d..50a4e620c6 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 @@ -157,7 +157,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp /** Cache of pre-filtered post-processors. */ @Nullable - private volatile BeanPostProcessorCache beanPostProcessorCache; + private BeanPostProcessorCache beanPostProcessorCache; /** Map from scope identifier String to corresponding Scope. */ private final Map scopes = new LinkedHashMap<>(8); @@ -926,10 +926,12 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @Override public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) { Assert.notNull(beanPostProcessor, "BeanPostProcessor must not be null"); - // Remove from old position, if any - this.beanPostProcessors.remove(beanPostProcessor); - // Add to end of list - this.beanPostProcessors.add(beanPostProcessor); + synchronized (this.beanPostProcessors) { + // Remove from old position, if any + this.beanPostProcessors.remove(beanPostProcessor); + // Add to end of list + this.beanPostProcessors.add(beanPostProcessor); + } } /** @@ -939,8 +941,12 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @see #addBeanPostProcessor */ public void addBeanPostProcessors(Collection beanPostProcessors) { - this.beanPostProcessors.removeAll(beanPostProcessors); - this.beanPostProcessors.addAll(beanPostProcessors); + synchronized (this.beanPostProcessors) { + // Remove from old position, if any + this.beanPostProcessors.removeAll(beanPostProcessors); + // Add to end of list + this.beanPostProcessors.addAll(beanPostProcessors); + } } @Override @@ -962,26 +968,34 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @since 5.3 */ BeanPostProcessorCache getBeanPostProcessorCache() { - BeanPostProcessorCache bppCache = this.beanPostProcessorCache; - if (bppCache == null) { - bppCache = new BeanPostProcessorCache(); - for (BeanPostProcessor bpp : this.beanPostProcessors) { - if (bpp instanceof InstantiationAwareBeanPostProcessor instantiationAwareBpp) { - bppCache.instantiationAware.add(instantiationAwareBpp); - if (bpp instanceof SmartInstantiationAwareBeanPostProcessor smartInstantiationAwareBpp) { - bppCache.smartInstantiationAware.add(smartInstantiationAwareBpp); + synchronized (this.beanPostProcessors) { + BeanPostProcessorCache bppCache = this.beanPostProcessorCache; + if (bppCache == null) { + bppCache = new BeanPostProcessorCache(); + for (BeanPostProcessor bpp : this.beanPostProcessors) { + if (bpp instanceof InstantiationAwareBeanPostProcessor instantiationAwareBpp) { + bppCache.instantiationAware.add(instantiationAwareBpp); + if (bpp instanceof SmartInstantiationAwareBeanPostProcessor smartInstantiationAwareBpp) { + bppCache.smartInstantiationAware.add(smartInstantiationAwareBpp); + } + } + if (bpp instanceof DestructionAwareBeanPostProcessor destructionAwareBpp) { + bppCache.destructionAware.add(destructionAwareBpp); + } + if (bpp instanceof MergedBeanDefinitionPostProcessor mergedBeanDefBpp) { + bppCache.mergedDefinition.add(mergedBeanDefBpp); } } - if (bpp instanceof DestructionAwareBeanPostProcessor destructionAwareBpp) { - bppCache.destructionAware.add(destructionAwareBpp); - } - if (bpp instanceof MergedBeanDefinitionPostProcessor mergedBeanDefBpp) { - bppCache.mergedDefinition.add(mergedBeanDefBpp); - } + this.beanPostProcessorCache = bppCache; } - this.beanPostProcessorCache = bppCache; + return bppCache; + } + } + + private void resetBeanPostProcessorCache() { + synchronized (this.beanPostProcessors) { + this.beanPostProcessorCache = null; } - return bppCache; } /** @@ -1937,27 +1951,27 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @Override public BeanPostProcessor set(int index, BeanPostProcessor element) { BeanPostProcessor result = super.set(index, element); - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); return result; } @Override public boolean add(BeanPostProcessor o) { boolean success = super.add(o); - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); return success; } @Override public void add(int index, BeanPostProcessor element) { super.add(index, element); - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } @Override public BeanPostProcessor remove(int index) { BeanPostProcessor result = super.remove(index); - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); return result; } @@ -1965,7 +1979,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean remove(Object o) { boolean success = super.remove(o); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -1974,7 +1988,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean removeAll(Collection c) { boolean success = super.removeAll(c); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -1983,7 +1997,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean retainAll(Collection c) { boolean success = super.retainAll(c); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -1992,7 +2006,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean addAll(Collection c) { boolean success = super.addAll(c); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -2001,7 +2015,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean addAll(int index, Collection c) { boolean success = super.addAll(index, c); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -2010,7 +2024,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp public boolean removeIf(Predicate filter) { boolean success = super.removeIf(filter); if (success) { - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } return success; } @@ -2018,7 +2032,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp @Override public void replaceAll(UnaryOperator operator) { super.replaceAll(operator); - beanPostProcessorCache = null; + resetBeanPostProcessorCache(); } }