Apply minor polishing in spring-aop

Closes gh-28984
This commit is contained in:
Adam Ostrožlík 2022-08-21 16:14:18 +02:00 committed by Sam Brannen
parent 33a0e65135
commit f2cdced501
5 changed files with 36 additions and 48 deletions

View File

@ -268,7 +268,6 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
this.argumentNames[i] + "' that is not a valid Java identifier"); this.argumentNames[i] + "' that is not a valid Java identifier");
} }
} }
if (this.argumentNames != null) {
if (this.aspectJAdviceMethod.getParameterCount() == this.argumentNames.length + 1) { if (this.aspectJAdviceMethod.getParameterCount() == this.argumentNames.length + 1) {
// May need to add implicit join point arg name... // May need to add implicit join point arg name...
Class<?> firstArgType = this.aspectJAdviceMethod.getParameterTypes()[0]; Class<?> firstArgType = this.aspectJAdviceMethod.getParameterTypes()[0];
@ -282,7 +281,6 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
} }
} }
} }
}
public void setReturningName(String name) { public void setReturningName(String name) {
throw new UnsupportedOperationException("Only afterReturning advice can be used to bind a return value"); throw new UnsupportedOperationException("Only afterReturning advice can be used to bind a return value");

View File

@ -108,14 +108,10 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
List<Element> childElts = DomUtils.getChildElements(element); List<Element> childElts = DomUtils.getChildElements(element);
for (Element elt: childElts) { for (Element elt: childElts) {
String localName = parserContext.getDelegate().getLocalName(elt); String localName = parserContext.getDelegate().getLocalName(elt);
if (POINTCUT.equals(localName)) { switch (localName) {
parsePointcut(elt, parserContext); case POINTCUT -> parsePointcut(elt, parserContext);
} case ADVISOR -> parseAdvisor(elt, parserContext);
else if (ADVISOR.equals(localName)) { case ASPECT -> parseAspect(elt, parserContext);
parseAdvisor(elt, parserContext);
}
else if (ASPECT.equals(localName)) {
parseAspect(elt, parserContext);
} }
} }

View File

@ -257,8 +257,7 @@ public abstract class AopProxyUtils {
if (ObjectUtils.isEmpty(arguments)) { if (ObjectUtils.isEmpty(arguments)) {
return new Object[0]; return new Object[0];
} }
if (method.isVarArgs()) { if (method.isVarArgs() && (method.getParameterCount() == arguments.length)) {
if (method.getParameterCount() == arguments.length) {
Class<?>[] paramTypes = method.getParameterTypes(); Class<?>[] paramTypes = method.getParameterTypes();
int varargIndex = paramTypes.length - 1; int varargIndex = paramTypes.length - 1;
Class<?> varargType = paramTypes[varargIndex]; Class<?> varargType = paramTypes[varargIndex];
@ -276,7 +275,6 @@ public abstract class AopProxyUtils {
} }
} }
} }
}
return arguments; return arguments;
} }

View File

@ -251,11 +251,10 @@ class CglibAopProxy implements AopProxy, Serializable {
private void validateClassIfNecessary(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader) { private void validateClassIfNecessary(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader) {
if (!this.advised.isOptimize() && logger.isInfoEnabled()) { if (!this.advised.isOptimize() && logger.isInfoEnabled()) {
synchronized (validatedClasses) { synchronized (validatedClasses) {
if (!validatedClasses.containsKey(proxySuperClass)) { validatedClasses.computeIfAbsent(proxySuperClass, clazz -> {
doValidateClass(proxySuperClass, proxyClassLoader, doValidateClass(clazz, proxyClassLoader, ClassUtils.getAllInterfacesForClassAsSet(clazz));
ClassUtils.getAllInterfacesForClassAsSet(proxySuperClass)); return Boolean.TRUE;
validatedClasses.put(proxySuperClass, Boolean.TRUE); });
}
} }
} }
} }
@ -702,8 +701,7 @@ class CglibAopProxy implements AopProxy, Serializable {
// We need to create a method invocation... // We need to create a method invocation...
retVal = new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed(); retVal = new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed();
} }
retVal = processReturnType(proxy, target, method, retVal); return processReturnType(proxy, target, method, retVal);
return retVal;
} }
finally { finally {
if (target != null && !targetSource.isStatic()) { if (target != null && !targetSource.isStatic()) {

View File

@ -109,12 +109,10 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
*/ */
private static boolean hasMatchingIntroductions(Advisor[] advisors, Class<?> actualClass) { private static boolean hasMatchingIntroductions(Advisor[] advisors, Class<?> actualClass) {
for (Advisor advisor : advisors) { for (Advisor advisor : advisors) {
if (advisor instanceof IntroductionAdvisor ia) { if (advisor instanceof IntroductionAdvisor ia && ia.getClassFilter().matches(actualClass)) {
if (ia.getClassFilter().matches(actualClass)) {
return true; return true;
} }
} }
}
return false; return false;
} }