diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index 1d7c74b811e..22a46e9456c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -655,10 +655,10 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence @Nullable protected JoinPointMatch getJoinPointMatch() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - return getJoinPointMatch((ProxyMethodInvocation) mi); + return getJoinPointMatch(pmi); } // Note: We can't use JoinPointMatch.getClass().getName() as the key, since diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java index 0d231809271..4ea59280d1b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAopUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -61,12 +61,12 @@ public abstract class AspectJAopUtils { */ @Nullable public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) { - if (anAdvisor instanceof AspectJPrecedenceInformation) { - return (AspectJPrecedenceInformation) anAdvisor; + if (anAdvisor instanceof AspectJPrecedenceInformation ajpi) { + return ajpi; } Advice advice = anAdvisor.getAdvice(); - if (advice instanceof AspectJPrecedenceInformation) { - return (AspectJPrecedenceInformation) advice; + if (advice instanceof AspectJPrecedenceInformation ajpi) { + return ajpi; } return null; } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 27281367b69..ced1c255612 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -200,8 +200,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut */ @Nullable private ClassLoader determinePointcutClassLoader() { - if (this.beanFactory instanceof ConfigurableBeanFactory) { - return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader(); + if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { + return cbf.getBeanClassLoader(); } if (this.pointcutDeclarationScope != null) { return this.pointcutDeclarationScope.getClassLoader(); @@ -335,10 +335,10 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut try { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); targetObject = mi.getThis(); - if (!(mi instanceof ProxyMethodInvocation)) { + if (!(mi instanceof ProxyMethodInvocation _pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } - pmi = (ProxyMethodInvocation) mi; + pmi = _pmi; thisObject = pmi.getProxy(); } catch (IllegalStateException ex) { @@ -404,8 +404,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut } private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch) { - if (shadowMatch instanceof DefensiveShadowMatch) { - return new RuntimeTestWalker(((DefensiveShadowMatch) shadowMatch).primary); + if (shadowMatch instanceof DefensiveShadowMatch defensiveShadowMatch) { + return new RuntimeTestWalker(defensiveShadowMatch.primary); } return new RuntimeTestWalker(shadowMatch); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java index e161007abe9..be7c8569404 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.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"); * you may not use this file except in compliance with the License. @@ -71,8 +71,8 @@ public abstract class AspectJProxyUtils { private static boolean isAspectJAdvice(Advisor advisor) { return (advisor instanceof InstantiationModelAwarePointcutAdvisor || advisor.getAdvice() instanceof AbstractAspectJAdvice || - (advisor instanceof PointcutAdvisor && - ((PointcutAdvisor) advisor).getPointcut() instanceof AspectJExpressionPointcut)); + (advisor instanceof PointcutAdvisor pointcutAdvisor && + pointcutAdvisor.getPointcut() instanceof AspectJExpressionPointcut)); } static boolean isVariableName(@Nullable String name) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java index 82e13b2bd2b..bf37296a6e8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -202,8 +202,8 @@ class RuntimeTestWalker { } Class typeClass = null; ResolvedType type = (ResolvedType) i.getType(); - if (type instanceof ReferenceType) { - ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate(); + if (type instanceof ReferenceType referenceType) { + ReferenceTypeDelegate delegate = referenceType.getDelegate(); if (delegate instanceof ReflectionBasedReferenceTypeDelegate) { try { ReflectionUtils.makeAccessible(myClassField); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java index 80447912c29..04edaa80766 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2022 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. @@ -69,8 +69,8 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory, Se */ @Override public int getOrder() { - if (this.aspectInstance instanceof Ordered) { - return ((Ordered) this.aspectInstance).getOrder(); + if (this.aspectInstance instanceof Ordered ordered) { + return ordered.getOrder(); } return getOrderForAspectClass(this.aspectInstance.getClass()); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java index cf1dcd929b1..ea26ec97912 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.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"); * you may not use this file except in compliance with the License. @@ -117,9 +117,9 @@ public class TypePatternClassFilter implements ClassFilter { } @Override - public boolean equals(Object other) { - return (this == other || (other instanceof TypePatternClassFilter && - ObjectUtils.nullSafeEquals(this.typePattern, ((TypePatternClassFilter) other).typePattern))); + public boolean equals(Object obj) { + return (this == obj || (obj instanceof TypePatternClassFilter that && + ObjectUtils.nullSafeEquals(this.typePattern, that.typePattern))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java index d5fefcec81d..3bdbb9c16ab 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -93,9 +93,8 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst @Override @Nullable public ClassLoader getAspectClassLoader() { - return (this.beanFactory instanceof ConfigurableBeanFactory ? - ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader() : - ClassUtils.getDefaultClassLoader()); + return (this.beanFactory instanceof ConfigurableBeanFactory cbf ? + cbf.getBeanClassLoader() : ClassUtils.getDefaultClassLoader()); } @Override @@ -110,11 +109,11 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst // Rely on singleton semantics provided by the factory -> no local lock. return null; } - else if (this.beanFactory instanceof ConfigurableBeanFactory) { + else if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { // No singleton guarantees from the factory -> let's lock locally but // reuse the factory's singleton lock, just in case a lazy dependency // of our advice bean happens to trigger the singleton lock implicitly... - return ((ConfigurableBeanFactory) this.beanFactory).getSingletonMutex(); + return cbf.getSingletonMutex(); } else { return this; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java index 33af3adfc30..f842e50ed9f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java @@ -274,8 +274,8 @@ final class InstantiationModelAwarePointcutAdvisorImpl this.declaredPointcut = declaredPointcut; this.preInstantiationPointcut = preInstantiationPointcut; - if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator) { - this.aspectInstanceFactory = (LazySingletonAspectInstanceFactoryDecorator) aspectInstanceFactory; + if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator lazyFactory) { + this.aspectInstanceFactory = lazyFactory; } } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java b/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java index 52a00db50c9..28fc6cdbb69 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.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"); * you may not use this file except in compliance with the License. @@ -93,8 +93,8 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement // copy autowire settings from original bean definition. proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate()); proxyDefinition.setPrimary(targetDefinition.isPrimary()); - if (targetDefinition instanceof AbstractBeanDefinition) { - proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition); + if (targetDefinition instanceof AbstractBeanDefinition abd) { + proxyDefinition.copyQualifiersFrom(abd); } // wrap it in a BeanDefinitionHolder with bean name result = new BeanDefinitionHolder(proxyDefinition, existingBeanName); diff --git a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java index fff18c0a4e4..b23dcf3d901 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/ConfigBeanDefinitionParser.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"); * you may not use this file except in compliance with the License. @@ -153,13 +153,13 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { } Object pointcut = parsePointcutProperty(advisorElement, parserContext); - if (pointcut instanceof BeanDefinition) { + if (pointcut instanceof BeanDefinition beanDefinition) { advisorDef.getPropertyValues().add(POINTCUT, pointcut); parserContext.registerComponent( - new AdvisorComponentDefinition(advisorBeanName, advisorDef, (BeanDefinition) pointcut)); + new AdvisorComponentDefinition(advisorBeanName, advisorDef, beanDefinition)); } - else if (pointcut instanceof String) { - advisorDef.getPropertyValues().add(POINTCUT, new RuntimeBeanReference((String) pointcut)); + else if (pointcut instanceof String beanName) { + advisorDef.getPropertyValues().add(POINTCUT, new RuntimeBeanReference(beanName)); parserContext.registerComponent( new AdvisorComponentDefinition(advisorBeanName, advisorDef)); } @@ -389,12 +389,12 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { cav.addIndexedArgumentValue(METHOD_INDEX, methodDef); Object pointcut = parsePointcutProperty(adviceElement, parserContext); - if (pointcut instanceof BeanDefinition) { + if (pointcut instanceof BeanDefinition beanDefinition) { cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut); - beanDefinitions.add((BeanDefinition) pointcut); + beanDefinitions.add(beanDefinition); } - else if (pointcut instanceof String) { - RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut); + else if (pointcut instanceof String beanName) { + RuntimeBeanReference pointcutRef = new RuntimeBeanReference(beanName); cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef); beanReferences.add(pointcutRef); } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java index 34a180a2c84..446d5f93e0a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java @@ -71,8 +71,8 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan @Override @Nullable public ClassLoader getAspectClassLoader() { - if (this.beanFactory instanceof ConfigurableBeanFactory) { - return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader(); + if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { + return cbf.getBeanClassLoader(); } else { return ClassUtils.getDefaultClassLoader(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java index 1c333af6944..68c54557a11 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java @@ -74,8 +74,9 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu // Use original ClassLoader if bean class not locally loaded in overriding class loader ClassLoader classLoader = getProxyClassLoader(); - if (classLoader instanceof SmartClassLoader && classLoader != beanClass.getClassLoader()) { - classLoader = ((SmartClassLoader) classLoader).getOriginalClassLoader(); + if (classLoader instanceof SmartClassLoader smartClassLoader && + classLoader != beanClass.getClassLoader()) { + classLoader = smartClassLoader.getOriginalClassLoader(); } return proxyFactory.getProxyClass(classLoader); } @@ -113,8 +114,9 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSu // Use original ClassLoader if bean class not locally loaded in overriding class loader ClassLoader classLoader = getProxyClassLoader(); - if (classLoader instanceof SmartClassLoader && classLoader != bean.getClass().getClassLoader()) { - classLoader = ((SmartClassLoader) classLoader).getOriginalClassLoader(); + if (classLoader instanceof SmartClassLoader smartClassLoader && + classLoader != bean.getClass().getClassLoader()) { + classLoader = smartClassLoader.getOriginalClassLoader(); } return proxyFactory.getProxy(classLoader); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java index bb680a3477b..cf40782c784 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -194,8 +194,8 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig * @return a TargetSource for this object */ protected TargetSource createTargetSource(Object target) { - if (target instanceof TargetSource) { - return (TargetSource) target; + if (target instanceof TargetSource targetSource) { + return targetSource; } else { return new SingletonTargetSource(target); @@ -229,8 +229,8 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig if (this.proxyInterfaces != null && this.proxyInterfaces.length == 1) { return this.proxyInterfaces[0]; } - if (this.target instanceof TargetSource) { - return ((TargetSource) this.target).getTargetClass(); + if (this.target instanceof TargetSource targetSource) { + return targetSource.getTargetClass(); } if (this.target != null) { return this.target.getClass(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index b6e192e7d35..90d5afef82d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -258,8 +258,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @Override public void addAdvisor(int pos, Advisor advisor) throws AopConfigException { - if (advisor instanceof IntroductionAdvisor) { - validateIntroductionAdvisor((IntroductionAdvisor) advisor); + if (advisor instanceof IntroductionAdvisor introductionAdvisor) { + validateIntroductionAdvisor(introductionAdvisor); } addAdvisorInternal(pos, advisor); } @@ -287,9 +287,9 @@ public class AdvisedSupport extends ProxyConfig implements Advised { } Advisor advisor = this.advisors.remove(index); - if (advisor instanceof IntroductionAdvisor ia) { + if (advisor instanceof IntroductionAdvisor introductionAdvisor) { // We need to remove introduction interfaces. - for (Class ifc : ia.getInterfaces()) { + for (Class ifc : introductionAdvisor.getInterfaces()) { removeInterface(ifc); } } @@ -387,10 +387,10 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @Override public void addAdvice(int pos, Advice advice) throws AopConfigException { Assert.notNull(advice, "Advice must not be null"); - if (advice instanceof IntroductionInfo) { + if (advice instanceof IntroductionInfo introductionInfo) { // We don't need an IntroductionAdvisor for this kind of introduction: // It's fully self-describing. - addAdvisor(pos, new DefaultIntroductionAdvisor(advice, (IntroductionInfo) advice)); + addAdvisor(pos, new DefaultIntroductionAdvisor(advice, introductionInfo)); } else if (advice instanceof DynamicIntroductionAdvice) { // We need an IntroductionAdvisor for this kind of introduction. @@ -506,8 +506,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised { this.advisorChainFactory = other.advisorChainFactory; this.interfaces = new ArrayList<>(other.interfaces); for (Advisor advisor : advisors) { - if (advisor instanceof IntroductionAdvisor) { - validateIntroductionAdvisor((IntroductionAdvisor) advisor); + if (advisor instanceof IntroductionAdvisor introductionAdvisor) { + validateIntroductionAdvisor(introductionAdvisor); } Assert.notNull(advisor, "Advisor must not be null"); this.advisors.add(advisor); @@ -580,8 +580,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @Override public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof MethodCacheKey && - this.method == ((MethodCacheKey) other).method)); + return (this == other || (other instanceof MethodCacheKey methodCacheKey && + this.method == methodCacheKey.method)); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index 4beff09bc34..d8a190298c1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -188,8 +188,8 @@ class CglibAopProxy implements AopProxy, Serializable { Enhancer enhancer = createEnhancer(); if (classLoader != null) { enhancer.setClassLoader(classLoader); - if (classLoader instanceof SmartClassLoader && - ((SmartClassLoader) classLoader).isClassReloadable(proxySuperClass)) { + if (classLoader instanceof SmartClassLoader smartClassLoader && + smartClassLoader.isClassReloadable(proxySuperClass)) { enhancer.setUseCache(false); } } @@ -365,8 +365,8 @@ class CglibAopProxy implements AopProxy, Serializable { @Override public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof CglibAopProxy && - AopProxyUtils.equalsInProxy(this.advised, ((CglibAopProxy) other).advised))); + return (this == other || (other instanceof CglibAopProxy cglibAopProxy && + AopProxyUtils.equalsInProxy(this.advised, cglibAopProxy.advised))); } @Override @@ -590,12 +590,12 @@ class CglibAopProxy implements AopProxy, Serializable { if (proxy == other) { return true; } - if (other instanceof Factory) { - Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS); - if (!(callback instanceof EqualsInterceptor)) { + if (other instanceof Factory factory) { + Callback callback = factory.getCallback(INVOKE_EQUALS); + if (!(callback instanceof EqualsInterceptor equalsInterceptor)) { return false; } - AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised; + AdvisedSupport otherAdvised = equalsInterceptor.advised; return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); } else { @@ -719,8 +719,8 @@ class CglibAopProxy implements AopProxy, Serializable { @Override public boolean equals(@Nullable Object other) { return (this == other || - (other instanceof DynamicAdvisedInterceptor && - this.advised.equals(((DynamicAdvisedInterceptor) other).advised))); + (other instanceof DynamicAdvisedInterceptor dynamicAdvisedInterceptor && + this.advised.equals(dynamicAdvisedInterceptor.advised))); } /** @@ -962,9 +962,9 @@ class CglibAopProxy implements AopProxy, Serializable { private static boolean equalsPointcuts(Advisor a, Advisor b) { // If only one of the advisor (but not both) is PointcutAdvisor, then it is a mismatch. // Takes care of the situations where an IntroductionAdvisor is used (see SPR-3959). - return (!(a instanceof PointcutAdvisor) || - (b instanceof PointcutAdvisor && - ObjectUtils.nullSafeEquals(((PointcutAdvisor) a).getPointcut(), ((PointcutAdvisor) b).getPointcut()))); + return (!(a instanceof PointcutAdvisor pointcutAdvisor1) || + (b instanceof PointcutAdvisor pointcutAdvisor2 && + ObjectUtils.nullSafeEquals(pointcutAdvisor1.getPointcut(), pointcutAdvisor2.getPointcut()))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java index 88c66b1ec7b..c313ad570e5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.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"); * you may not use this file except in compliance with the License. diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java index 81b48229ef3..d6a45a9fc92 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java @@ -262,15 +262,15 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa } JdkDynamicAopProxy otherProxy; - if (other instanceof JdkDynamicAopProxy) { - otherProxy = (JdkDynamicAopProxy) other; + if (other instanceof JdkDynamicAopProxy jdkDynamicAopProxy) { + otherProxy = jdkDynamicAopProxy; } else if (Proxy.isProxyClass(other.getClass())) { InvocationHandler ih = Proxy.getInvocationHandler(other); - if (!(ih instanceof JdkDynamicAopProxy)) { + if (!(ih instanceof JdkDynamicAopProxy jdkDynamicAopProxy)) { return false; } - otherProxy = (JdkDynamicAopProxy) ih; + otherProxy = jdkDynamicAopProxy; } else { // Not a valid comparison... diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationManager.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationManager.java index c9a4af84787..6589fffd19b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationManager.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistrationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2022 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. @@ -55,8 +55,8 @@ public class AdvisorAdapterRegistrationManager implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof AdvisorAdapter){ - this.advisorAdapterRegistry.registerAdvisorAdapter((AdvisorAdapter) bean); + if (bean instanceof AdvisorAdapter advisorAdapter) { + this.advisorAdapterRegistry.registerAdvisorAdapter(advisorAdapter); } return bean; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java index 9335a1f5a01..e1a92b241d3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.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"); * you may not use this file except in compliance with the License. @@ -55,8 +55,8 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se @Override public Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException { - if (adviceObject instanceof Advisor) { - return (Advisor) adviceObject; + if (adviceObject instanceof Advisor advisor) { + return advisor; } if (!(adviceObject instanceof Advice advice)) { throw new UnknownAdviceTypeException(adviceObject); @@ -78,8 +78,8 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se public MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException { List interceptors = new ArrayList<>(3); Advice advice = advisor.getAdvice(); - if (advice instanceof MethodInterceptor) { - interceptors.add((MethodInterceptor) advice); + if (advice instanceof MethodInterceptor methodInterceptor) { + interceptors.add(methodInterceptor); } for (AdvisorAdapter adapter : this.adapters) { if (adapter.supportsAdvice(advice)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java index 4900c3d4657..ca048cb9f17 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.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"); * you may not use this file except in compliance with the License. @@ -58,11 +58,11 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC @Override public void setBeanFactory(BeanFactory beanFactory) { super.setBeanFactory(beanFactory); - if (!(beanFactory instanceof ConfigurableListableBeanFactory)) { + if (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) { throw new IllegalArgumentException( "AdvisorAutoProxyCreator requires a ConfigurableListableBeanFactory: " + beanFactory); } - initBeanFactory((ConfigurableListableBeanFactory) beanFactory); + initBeanFactory(clbf); } protected void initBeanFactory(ConfigurableListableBeanFactory beanFactory) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index f6363db6a43..502fd9e2925 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -473,8 +473,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport private Object buildProxy(Class beanClass, @Nullable String beanName, @Nullable Object[] specificInterceptors, TargetSource targetSource, boolean classOnly) { - if (this.beanFactory instanceof ConfigurableListableBeanFactory) { - AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass); + if (this.beanFactory instanceof ConfigurableListableBeanFactory clbf) { + AutoProxyUtils.exposeTargetClass(clbf, beanName, beanClass); } ProxyFactory proxyFactory = new ProxyFactory(); @@ -511,8 +511,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport // Use original ClassLoader if bean class not locally loaded in overriding class loader ClassLoader classLoader = getProxyClassLoader(); - if (classLoader instanceof SmartClassLoader && classLoader != beanClass.getClassLoader()) { - classLoader = ((SmartClassLoader) classLoader).getOriginalClassLoader(); + if (classLoader instanceof SmartClassLoader smartClassLoader && classLoader != beanClass.getClassLoader()) { + classLoader = smartClassLoader.getOriginalClassLoader(); } return (classOnly ? proxyFactory.getProxyClass(classLoader) : proxyFactory.getProxy(classLoader)); } @@ -527,8 +527,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @see AutoProxyUtils#shouldProxyTargetClass */ protected boolean shouldProxyTargetClass(Class beanClass, @Nullable String beanName) { - return (this.beanFactory instanceof ConfigurableListableBeanFactory && - AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName)); + return (this.beanFactory instanceof ConfigurableListableBeanFactory clbf && + AutoProxyUtils.shouldProxyTargetClass(clbf, beanName)); } /** @@ -592,7 +592,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport */ private Advisor[] resolveInterceptorNames() { BeanFactory bf = this.beanFactory; - ConfigurableBeanFactory cbf = (bf instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) bf : null); + ConfigurableBeanFactory cbf = (bf instanceof ConfigurableBeanFactory _cbf ? _cbf : null); List advisors = new ArrayList<>(); for (String beanName : this.interceptorNames) { if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java index 280eb9b23a6..0dbea8a467f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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,8 +46,7 @@ public abstract class AbstractBeanFactoryAwareAdvisingPostProcessor extends Abst @Override public void setBeanFactory(BeanFactory beanFactory) { - this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory ? - (ConfigurableListableBeanFactory) beanFactory : null); + this.beanFactory = (beanFactory instanceof ConfigurableListableBeanFactory clbf ? clbf : null); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java index fcef74b56ef..ff9a03f15cf 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/AbstractBeanFactoryBasedTargetSourceCreator.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"); * you may not use this file except in compliance with the License. @@ -67,11 +67,11 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator @Override public final void setBeanFactory(BeanFactory beanFactory) { - if (!(beanFactory instanceof ConfigurableBeanFactory)) { + if (!(beanFactory instanceof ConfigurableBeanFactory clbf)) { throw new IllegalStateException("Cannot do auto-TargetSource creation with a BeanFactory " + "that doesn't implement ConfigurableBeanFactory: " + beanFactory.getClass()); } - this.beanFactory = (ConfigurableBeanFactory) beanFactory; + this.beanFactory = clbf; } /** diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java index 01aa62b7607..68ca0524471 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.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"); * you may not use this file except in compliance with the License. @@ -66,9 +66,8 @@ public class LazyInitTargetSourceCreator extends AbstractBeanFactoryBasedTargetS protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( Class beanClass, String beanName) { - if (getBeanFactory() instanceof ConfigurableListableBeanFactory) { - BeanDefinition definition = - ((ConfigurableListableBeanFactory) getBeanFactory()).getBeanDefinition(beanName); + if (getBeanFactory() instanceof ConfigurableListableBeanFactory clbf) { + BeanDefinition definition = clbf.getBeanDefinition(beanName); if (definition.isLazyInit()) { return new LazyInitTargetSource(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java index 5cef18836f8..5d35e87994b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java @@ -182,8 +182,8 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { if (targetExecutor == null) { return null; } - executor = (targetExecutor instanceof AsyncTaskExecutor ? - (AsyncTaskExecutor) targetExecutor : new TaskExecutorAdapter(targetExecutor)); + executor = (targetExecutor instanceof AsyncTaskExecutor asyncTaskExecutor ? + asyncTaskExecutor : new TaskExecutorAdapter(targetExecutor)); this.executors.put(method, executor); } return executor; diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java index a466164bcc7..d585df32a49 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.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"); * you may not use this file except in compliance with the License. @@ -113,8 +113,8 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple Callable task = () -> { try { Object result = invocation.proceed(); - if (result instanceof Future) { - return ((Future) result).get(); + if (result instanceof Future future) { + return future.get(); } } catch (ExecutionException ex) { diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java index 7f71d3a3fc4..23e5cf64b88 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java @@ -75,7 +75,7 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc @Nullable private String getTargetBeanName(BeanDefinition beanDefinition) { Object value = beanDefinition.getPropertyValues().get("targetBeanName"); - return (value instanceof String ? (String) value : null); + return (value instanceof String targetBeanName ? targetBeanName : null); } @Nullable diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java index ccb008ebd01..f9efdc469ad 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.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"); * you may not use this file except in compliance with the License. @@ -82,8 +82,8 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu } private void resetAdviceMonitor() { - if (this.beanFactory instanceof ConfigurableBeanFactory) { - this.adviceMonitor = ((ConfigurableBeanFactory) this.beanFactory).getSingletonMutex(); + if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { + this.adviceMonitor = cbf.getSingletonMutex(); } else { this.adviceMonitor = new Object(); diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java index 0b821ce76dc..dcc8670f870 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java @@ -107,8 +107,8 @@ public abstract class AopUtils { public static Class getTargetClass(Object candidate) { Assert.notNull(candidate, "Candidate object must not be null"); Class result = null; - if (candidate instanceof TargetClassAware) { - result = ((TargetClassAware) candidate).getTargetClass(); + if (candidate instanceof TargetClassAware targetClassAware) { + result = targetClassAware.getTargetClass(); } if (result == null) { result = (isCglibProxy(candidate) ? candidate.getClass().getSuperclass() : candidate.getClass()); @@ -234,8 +234,8 @@ public abstract class AopUtils { } IntroductionAwareMethodMatcher introductionAwareMethodMatcher = null; - if (methodMatcher instanceof IntroductionAwareMethodMatcher) { - introductionAwareMethodMatcher = (IntroductionAwareMethodMatcher) methodMatcher; + if (methodMatcher instanceof IntroductionAwareMethodMatcher iamm) { + introductionAwareMethodMatcher = iamm; } Set> classes = new LinkedHashSet<>(); @@ -281,8 +281,8 @@ public abstract class AopUtils { * @return whether the pointcut can apply on any method */ public static boolean canApply(Advisor advisor, Class targetClass, boolean hasIntroductions) { - if (advisor instanceof IntroductionAdvisor) { - return ((IntroductionAdvisor) advisor).getClassFilter().matches(targetClass); + if (advisor instanceof IntroductionAdvisor ia) { + return ia.getClassFilter().matches(targetClass); } else if (advisor instanceof PointcutAdvisor pca) { return canApply(pca.getPointcut(), targetClass, hasIntroductions); diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java index 6f624ca14b7..b0c2c65c6db 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.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"); * you may not use this file except in compliance with the License. @@ -109,9 +109,9 @@ public abstract class ClassFilters { } @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof UnionClassFilter && - ObjectUtils.nullSafeEquals(this.filters, ((UnionClassFilter) other).filters))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof UnionClassFilter that && + ObjectUtils.nullSafeEquals(this.filters, that.filters))); } @Override @@ -150,9 +150,9 @@ public abstract class ClassFilters { } @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof IntersectionClassFilter && - ObjectUtils.nullSafeEquals(this.filters, ((IntersectionClassFilter) other).filters))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof IntersectionClassFilter that && + ObjectUtils.nullSafeEquals(this.filters, that.filters))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index 5fefc059f36..8b70d019fe8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.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"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil * @see #addInterface */ public DefaultIntroductionAdvisor(Advice advice) { - this(advice, (advice instanceof IntroductionInfo ? (IntroductionInfo) advice : null)); + this(advice, (advice instanceof IntroductionInfo introductionInfo ? introductionInfo : null)); } /** @@ -112,8 +112,8 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil @Override public void validateInterfaces() throws IllegalArgumentException { for (Class ifc : this.interfaces) { - if (this.advice instanceof DynamicIntroductionAdvice && - !((DynamicIntroductionAdvice) this.advice).implementsInterface(ifc)) { + if (this.advice instanceof DynamicIntroductionAdvice dynamicIntroductionAdvice && + !dynamicIntroductionAdvice.implementsInterface(ifc)) { throw new IllegalArgumentException("DynamicIntroductionAdvice [" + this.advice + "] " + "does not implement interface [" + ifc.getName() + "] specified for introduction"); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java index 299a474a64e..0f3d511c0de 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.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"); * you may not use this file except in compliance with the License. @@ -98,8 +98,8 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. - if (retVal == delegate && mi instanceof ProxyMethodInvocation) { - retVal = ((ProxyMethodInvocation) mi).getProxy(); + if (retVal == delegate && mi instanceof ProxyMethodInvocation pmi) { + retVal = pmi.getProxy(); } return retVal; } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java index c7c5981fd38..bd9647a0f46 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.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"); * you may not use this file except in compliance with the License. @@ -112,8 +112,8 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport // Massage return value if possible: if the delegate returned itself, // we really want to return the proxy. - if (retVal == this.delegate && mi instanceof ProxyMethodInvocation) { - Object proxy = ((ProxyMethodInvocation) mi).getProxy(); + if (retVal == this.delegate && mi instanceof ProxyMethodInvocation pmi) { + Object proxy = pmi.getProxy(); if (mi.getMethod().getReturnType().isInstance(proxy)) { retVal = proxy; } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index d3d762465d5..5c81794a92b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.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"); * you may not use this file except in compliance with the License. @@ -100,9 +100,9 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof NameMatchMethodPointcut && - this.mappedNames.equals(((NameMatchMethodPointcut) other).mappedNames))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof NameMatchMethodPointcut that && + this.mappedNames.equals(that.mappedNames))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java index 3809a303797..cd371a80562 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.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"); * you may not use this file except in compliance with the License. @@ -45,9 +45,9 @@ public class RootClassFilter implements ClassFilter, Serializable { } @Override - public boolean equals(Object other) { - return (this == other || (other instanceof RootClassFilter && - this.clazz.equals(((RootClassFilter) other).clazz))); + public boolean equals(Object obj) { + return (this == obj || (obj instanceof RootClassFilter that && + this.clazz.equals(that.clazz))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java index b3c564743b8..0824efc4678 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPrototypeBasedTargetSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -77,12 +77,12 @@ public abstract class AbstractPrototypeBasedTargetSource extends AbstractBeanFac if (logger.isDebugEnabled()) { logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'"); } - if (getBeanFactory() instanceof ConfigurableBeanFactory) { - ((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target); + if (getBeanFactory() instanceof ConfigurableBeanFactory cbf) { + cbf.destroyBean(getTargetBeanName(), target); } - else if (target instanceof DisposableBean) { + else if (target instanceof DisposableBean disposableBean) { try { - ((DisposableBean) target).destroy(); + disposableBean.destroy(); } catch (Throwable ex) { logger.warn("Destroy method on bean with name '" + getTargetBeanName() + "' threw an exception", ex); diff --git a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java index 99ffaeabde4..3bf01a6b652 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java @@ -100,9 +100,9 @@ public class HotSwappableTargetSource implements TargetSource, Serializable { * objects are equal. */ @Override - public boolean equals(Object other) { - return (this == other || (other instanceof HotSwappableTargetSource && - this.target.equals(((HotSwappableTargetSource) other).target))); + public boolean equals(Object obj) { + return (this == obj || (obj instanceof HotSwappableTargetSource that && + this.target.equals(that.target))); } @Override