Browse Source

Apply 'instanceof pattern matching'

pull/29557/head
Sam Brannen 3 years ago
parent
commit
d32027df92
  1. 4
      spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java
  2. 4
      spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java
  3. 31
      spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  4. 14
      spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java
  5. 46
      spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java
  6. 15
      spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java
  7. 20
      spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java
  8. 4
      spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java
  9. 6
      spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java
  10. 8
      spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java
  11. 6
      spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

4
spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,7 +36,7 @@ public class BeanExpressionContextAccessor implements PropertyAccessor {
@Override @Override
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException { public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
return (target instanceof BeanExpressionContext && ((BeanExpressionContext) target).containsObject(name)); return (target instanceof BeanExpressionContext bec && bec.containsObject(name));
} }
@Override @Override

4
spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ public class BeanFactoryAccessor implements PropertyAccessor {
@Override @Override
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException { public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
return (target instanceof BeanFactory && ((BeanFactory) target).containsBean(name)); return (target instanceof BeanFactory beanFactory && beanFactory.containsBean(name));
} }
@Override @Override

31
spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -395,8 +395,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Decorate event as an ApplicationEvent if necessary // Decorate event as an ApplicationEvent if necessary
ApplicationEvent applicationEvent; ApplicationEvent applicationEvent;
if (event instanceof ApplicationEvent) { if (event instanceof ApplicationEvent applEvent) {
applicationEvent = (ApplicationEvent) event; applicationEvent = applEvent;
} }
else { else {
applicationEvent = new PayloadApplicationEvent<>(this, event, eventType); applicationEvent = new PayloadApplicationEvent<>(this, event, eventType);
@ -415,8 +415,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Publish event via parent context as well... // Publish event via parent context as well...
if (this.parent != null) { if (this.parent != null) {
if (this.parent instanceof AbstractApplicationContext) { if (this.parent instanceof AbstractApplicationContext abstractApplicationContext) {
((AbstractApplicationContext) this.parent).publishEvent(event, eventType); abstractApplicationContext.publishEvent(event, eventType);
} }
else { else {
this.parent.publishEvent(event); this.parent.publishEvent(event);
@ -497,8 +497,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
this.parent = parent; this.parent = parent;
if (parent != null) { if (parent != null) {
Environment parentEnvironment = parent.getEnvironment(); Environment parentEnvironment = parent.getEnvironment();
if (parentEnvironment instanceof ConfigurableEnvironment) { if (parentEnvironment instanceof ConfigurableEnvironment configurableEnvironment) {
getEnvironment().merge((ConfigurableEnvironment) parentEnvironment); getEnvironment().merge(configurableEnvironment);
} }
} }
} }
@ -770,12 +770,11 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) { if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class); this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
// Make MessageSource aware of parent MessageSource. // Make MessageSource aware of parent MessageSource.
if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource hms) { if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource hms &&
if (hms.getParentMessageSource() == null) { hms.getParentMessageSource() == null) {
// Only set parent context as parent MessageSource if no parent MessageSource // Only set parent context as parent MessageSource if no parent MessageSource
// registered already. // registered already.
hms.setParentMessageSource(getInternalParentMessageSource()); hms.setParentMessageSource(getInternalParentMessageSource());
}
} }
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Using MessageSource [" + this.messageSource + "]"); logger.trace("Using MessageSource [" + this.messageSource + "]");
@ -1350,8 +1349,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
*/ */
@Nullable @Nullable
protected BeanFactory getInternalParentBeanFactory() { protected BeanFactory getInternalParentBeanFactory() {
return (getParent() instanceof ConfigurableApplicationContext ? return (getParent() instanceof ConfigurableApplicationContext cac ?
((ConfigurableApplicationContext) getParent()).getBeanFactory() : getParent()); cac.getBeanFactory() : getParent());
} }
@ -1393,8 +1392,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
*/ */
@Nullable @Nullable
protected MessageSource getInternalParentMessageSource() { protected MessageSource getInternalParentMessageSource() {
return (getParent() instanceof AbstractApplicationContext ? return (getParent() instanceof AbstractApplicationContext abstractApplicationContext ?
((AbstractApplicationContext) getParent()).messageSource : getParent()); abstractApplicationContext.messageSource : getParent());
} }

14
spring-context/src/main/java/org/springframework/context/support/AbstractMessageSource.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -255,10 +255,10 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
protected String getMessageFromParent(String code, @Nullable Object[] args, Locale locale) { protected String getMessageFromParent(String code, @Nullable Object[] args, Locale locale) {
MessageSource parent = getParentMessageSource(); MessageSource parent = getParentMessageSource();
if (parent != null) { if (parent != null) {
if (parent instanceof AbstractMessageSource) { if (parent instanceof AbstractMessageSource abstractMessageSource) {
// Call internal method to avoid getting the default code back // Call internal method to avoid getting the default code back
// in case of "useCodeAsDefaultMessage" being activated. // in case of "useCodeAsDefaultMessage" being activated.
return ((AbstractMessageSource) parent).getMessageInternal(code, args, locale); return abstractMessageSource.getMessageInternal(code, args, locale);
} }
else { else {
// Check parent MessageSource, returning null if not found there. // Check parent MessageSource, returning null if not found there.
@ -287,8 +287,8 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
String defaultMessage = resolvable.getDefaultMessage(); String defaultMessage = resolvable.getDefaultMessage();
String[] codes = resolvable.getCodes(); String[] codes = resolvable.getCodes();
if (defaultMessage != null) { if (defaultMessage != null) {
if (resolvable instanceof DefaultMessageSourceResolvable && if (resolvable instanceof DefaultMessageSourceResolvable defaultMessageSourceResolvable &&
!((DefaultMessageSourceResolvable) resolvable).shouldRenderDefaultMessage()) { !defaultMessageSourceResolvable.shouldRenderDefaultMessage()) {
// Given default message does not contain any argument placeholders // Given default message does not contain any argument placeholders
// (and isn't escaped for alwaysUseMessageFormat either) -> return as-is. // (and isn't escaped for alwaysUseMessageFormat either) -> return as-is.
return defaultMessage; return defaultMessage;
@ -336,8 +336,8 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
} }
List<Object> resolvedArgs = new ArrayList<>(args.length); List<Object> resolvedArgs = new ArrayList<>(args.length);
for (Object arg : args) { for (Object arg : args) {
if (arg instanceof MessageSourceResolvable) { if (arg instanceof MessageSourceResolvable messageSourceResolvable) {
resolvedArgs.add(getMessage((MessageSourceResolvable) arg, locale)); resolvedArgs.add(getMessage(messageSourceResolvable, locale));
} }
else { else {
resolvedArgs.add(arg); resolvedArgs.add(arg);

46
spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.context.support; package org.springframework.context.support;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.Aware;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.EmbeddedValueResolver; import org.springframework.beans.factory.config.EmbeddedValueResolver;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@ -47,6 +48,7 @@ import org.springframework.util.StringValueResolver;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Costin Leau * @author Costin Leau
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen
* @since 10.10.2003 * @since 10.10.2003
* @see org.springframework.context.EnvironmentAware * @see org.springframework.context.EnvironmentAware
* @see org.springframework.context.EmbeddedValueResolverAware * @see org.springframework.context.EmbeddedValueResolverAware
@ -87,26 +89,28 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
} }
private void invokeAwareInterfaces(Object bean) { private void invokeAwareInterfaces(Object bean) {
if (bean instanceof EnvironmentAware) { if (bean instanceof Aware) {
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment()); if (bean instanceof EnvironmentAware environmentAware) {
} environmentAware.setEnvironment(this.applicationContext.getEnvironment());
if (bean instanceof EmbeddedValueResolverAware) { }
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver); if (bean instanceof EmbeddedValueResolverAware embeddedValueResolverAware) {
} embeddedValueResolverAware.setEmbeddedValueResolver(this.embeddedValueResolver);
if (bean instanceof ResourceLoaderAware) { }
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext); if (bean instanceof ResourceLoaderAware resourceLoaderAware) {
} resourceLoaderAware.setResourceLoader(this.applicationContext);
if (bean instanceof ApplicationEventPublisherAware) { }
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext); if (bean instanceof ApplicationEventPublisherAware applicationEventPublisherAware) {
} applicationEventPublisherAware.setApplicationEventPublisher(this.applicationContext);
if (bean instanceof MessageSourceAware) { }
((MessageSourceAware) bean).setMessageSource(this.applicationContext); if (bean instanceof MessageSourceAware messageSourceAware) {
} messageSourceAware.setMessageSource(this.applicationContext);
if (bean instanceof ApplicationStartupAware) { }
((ApplicationStartupAware) bean).setApplicationStartup(this.applicationContext.getApplicationStartup()); if (bean instanceof ApplicationStartupAware applicationStartupAware) {
} applicationStartupAware.setApplicationStartup(this.applicationContext.getApplicationStartup());
if (bean instanceof ApplicationContextAware) { }
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext); if (bean instanceof ApplicationContextAware applicationContextAware) {
applicationContextAware.setApplicationContext(this.applicationContext);
}
} }
} }

15
spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -71,12 +71,12 @@ class ApplicationListenerDetector implements DestructionAwareBeanPostProcessor,
@Override @Override
public Object postProcessAfterInitialization(Object bean, String beanName) { public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof ApplicationListener) { if (bean instanceof ApplicationListener<?> applicationListener) {
// potentially not detected as a listener by getBeanNamesForType retrieval // potentially not detected as a listener by getBeanNamesForType retrieval
Boolean flag = this.singletonNames.get(beanName); Boolean flag = this.singletonNames.get(beanName);
if (Boolean.TRUE.equals(flag)) { if (Boolean.TRUE.equals(flag)) {
// singleton bean (top-level or inner): register on the fly // singleton bean (top-level or inner): register on the fly
this.applicationContext.addApplicationListener((ApplicationListener<?>) bean); this.applicationContext.addApplicationListener(applicationListener);
} }
else if (Boolean.FALSE.equals(flag)) { else if (Boolean.FALSE.equals(flag)) {
if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) { if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) {
@ -94,10 +94,10 @@ class ApplicationListenerDetector implements DestructionAwareBeanPostProcessor,
@Override @Override
public void postProcessBeforeDestruction(Object bean, String beanName) { public void postProcessBeforeDestruction(Object bean, String beanName) {
if (bean instanceof ApplicationListener) { if (bean instanceof ApplicationListener<?> applicationListener) {
try { try {
ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster(); ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster();
multicaster.removeApplicationListener((ApplicationListener<?>) bean); multicaster.removeApplicationListener(applicationListener);
multicaster.removeApplicationListenerBean(beanName); multicaster.removeApplicationListenerBean(beanName);
} }
catch (IllegalStateException ex) { catch (IllegalStateException ex) {
@ -114,8 +114,9 @@ class ApplicationListenerDetector implements DestructionAwareBeanPostProcessor,
@Override @Override
public boolean equals(@Nullable Object other) { public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ApplicationListenerDetector && return (this == other ||
this.applicationContext == ((ApplicationListenerDetector) other).applicationContext)); (other instanceof ApplicationListenerDetector applicationListenerDectector &&
this.applicationContext == applicationListenerDectector.applicationContext));
} }
@Override @Override

20
spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -74,11 +74,11 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
@Override @Override
public void setBeanFactory(BeanFactory beanFactory) { public void setBeanFactory(BeanFactory beanFactory) {
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) { if (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"DefaultLifecycleProcessor requires a ConfigurableListableBeanFactory: " + beanFactory); "DefaultLifecycleProcessor requires a ConfigurableListableBeanFactory: " + beanFactory);
} }
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory; this.beanFactory = clbf;
} }
private ConfigurableListableBeanFactory getBeanFactory() { private ConfigurableListableBeanFactory getBeanFactory() {
@ -143,7 +143,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
Map<Integer, LifecycleGroup> phases = new TreeMap<>(); Map<Integer, LifecycleGroup> phases = new TreeMap<>();
lifecycleBeans.forEach((beanName, bean) -> { lifecycleBeans.forEach((beanName, bean) -> {
if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup())) { if (!autoStartupOnly || (bean instanceof SmartLifecycle smartLifecycle && smartLifecycle.isAutoStartup())) {
int phase = getPhase(bean); int phase = getPhase(bean);
phases.computeIfAbsent( phases.computeIfAbsent(
phase, phase,
@ -170,7 +170,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
doStart(lifecycleBeans, dependency, autoStartupOnly); doStart(lifecycleBeans, dependency, autoStartupOnly);
} }
if (!bean.isRunning() && if (!bean.isRunning() &&
(!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) { (!autoStartupOnly || !(bean instanceof SmartLifecycle smartLifecycle) || smartLifecycle.isAutoStartup())) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]"); logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]");
} }
@ -225,13 +225,13 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
} }
try { try {
if (bean.isRunning()) { if (bean.isRunning()) {
if (bean instanceof SmartLifecycle) { if (bean instanceof SmartLifecycle smartLifecycle) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("Asking bean '" + beanName + "' of type [" + logger.trace("Asking bean '" + beanName + "' of type [" +
bean.getClass().getName() + "] to stop"); bean.getClass().getName() + "] to stop");
} }
countDownBeanNames.add(beanName); countDownBeanNames.add(beanName);
((SmartLifecycle) bean).stop(() -> { smartLifecycle.stop(() -> {
latch.countDown(); latch.countDown();
countDownBeanNames.remove(beanName); countDownBeanNames.remove(beanName);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
@ -283,8 +283,8 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
(!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck, beanFactory))) || (!isFactoryBean || matchesBeanType(Lifecycle.class, beanNameToCheck, beanFactory))) ||
matchesBeanType(SmartLifecycle.class, beanNameToCheck, beanFactory)) { matchesBeanType(SmartLifecycle.class, beanNameToCheck, beanFactory)) {
Object bean = beanFactory.getBean(beanNameToCheck); Object bean = beanFactory.getBean(beanNameToCheck);
if (bean != this && bean instanceof Lifecycle) { if (bean != this && bean instanceof Lifecycle lifecycle) {
beans.put(beanNameToRegister, (Lifecycle) bean); beans.put(beanNameToRegister, lifecycle);
} }
} }
} }
@ -306,7 +306,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
* @see SmartLifecycle * @see SmartLifecycle
*/ */
protected int getPhase(Lifecycle bean) { protected int getPhase(Lifecycle bean) {
return (bean instanceof Phased ? ((Phased) bean).getPhase() : 0); return (bean instanceof Phased phased ? phased.getPhase() : 0);
} }

4
spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

@ -272,8 +272,8 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
*/ */
@Override @Override
public Resource[] getResources(String locationPattern) throws IOException { public Resource[] getResources(String locationPattern) throws IOException {
if (this.resourceLoader instanceof ResourcePatternResolver) { if (this.resourceLoader instanceof ResourcePatternResolver resourcePatternResolver) {
return ((ResourcePatternResolver) this.resourceLoader).getResources(locationPattern); return resourcePatternResolver.getResources(locationPattern);
} }
return super.getResources(locationPattern); return super.getResources(locationPattern);
} }

6
spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -242,8 +242,8 @@ public class GenericGroovyApplicationContext extends GenericApplicationContext i
@Override @Override
public void setProperty(String property, Object newValue) { public void setProperty(String property, Object newValue) {
if (newValue instanceof BeanDefinition) { if (newValue instanceof BeanDefinition beanDefinition) {
registerBeanDefinition(property, (BeanDefinition) newValue); registerBeanDefinition(property, beanDefinition);
} }
else { else {
this.metaClass.setProperty(this, property, newValue); this.metaClass.setProperty(this, property, newValue);

8
spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java

@ -323,8 +323,8 @@ final class PostProcessorRegistrationDelegate {
return; return;
} }
Comparator<Object> comparatorToUse = null; Comparator<Object> comparatorToUse = null;
if (beanFactory instanceof DefaultListableBeanFactory) { if (beanFactory instanceof DefaultListableBeanFactory dlbf) {
comparatorToUse = ((DefaultListableBeanFactory) beanFactory).getDependencyComparator(); comparatorToUse = dlbf.getDependencyComparator();
} }
if (comparatorToUse == null) { if (comparatorToUse == null) {
comparatorToUse = OrderComparator.INSTANCE; comparatorToUse = OrderComparator.INSTANCE;
@ -366,9 +366,9 @@ final class PostProcessorRegistrationDelegate {
private static void registerBeanPostProcessors( private static void registerBeanPostProcessors(
ConfigurableListableBeanFactory beanFactory, List<? extends BeanPostProcessor> postProcessors) { ConfigurableListableBeanFactory beanFactory, List<? extends BeanPostProcessor> postProcessors) {
if (beanFactory instanceof AbstractBeanFactory) { if (beanFactory instanceof AbstractBeanFactory abstractBeanFactory) {
// Bulk addition is more efficient against our CopyOnWriteArrayList there // Bulk addition is more efficient against our CopyOnWriteArrayList there
((AbstractBeanFactory) beanFactory).addBeanPostProcessors(postProcessors); abstractBeanFactory.addBeanPostProcessors(postProcessors);
} }
else { else {
for (BeanPostProcessor postProcessor : postProcessors) { for (BeanPostProcessor postProcessor : postProcessors) {

6
spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -534,8 +534,8 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
*/ */
public void clearCacheIncludingAncestors() { public void clearCacheIncludingAncestors() {
clearCache(); clearCache();
if (getParentMessageSource() instanceof ReloadableResourceBundleMessageSource) { if (getParentMessageSource() instanceof ReloadableResourceBundleMessageSource reloadableMsgSrc) {
((ReloadableResourceBundleMessageSource) getParentMessageSource()).clearCacheIncludingAncestors(); reloadableMsgSrc.clearCacheIncludingAncestors();
} }
} }

Loading…
Cancel
Save