From a2d40f3f1669c5472332bb04fb0941f5c104e264 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 4 Jan 2014 22:48:06 +0100 Subject: [PATCH] Polishing --- .../aop/framework/CglibAopProxy.java | 23 ++++++++----------- .../aop/framework/ObjenesisCglibAopProxy.java | 9 ++++---- .../support/AbstractRegexpMethodPointcut.java | 8 +++---- .../aop/support/ComposablePointcut.java | 7 ++---- 4 files changed, 20 insertions(+), 27 deletions(-) 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 7f934c3e367..5a16754b70d 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 @@ -219,12 +219,11 @@ class CglibAopProxy implements AopProxy, Serializable { } protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) { - enhancer.setInterceptDuringConstruction(false); enhancer.setCallbacks(callbacks); - - return this.constructorArgs == null ? enhancer.create() : enhancer.create( - this.constructorArgTypes, this.constructorArgs); + return (this.constructorArgs != null ? + enhancer.create(this.constructorArgTypes, this.constructorArgs) : + enhancer.create()); } /** @@ -314,8 +313,7 @@ class CglibAopProxy implements AopProxy, Serializable { Callback[] fixedCallbacks = new Callback[methods.length]; this.fixedInterceptorMap = new HashMap(methods.length); - // TODO: small memory optimisation here (can skip creation for - // methods with no advice) + // TODO: small memory optimisation here (can skip creation for methods with no advice) for (int x = 0; x < methods.length; x++) { List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass); fixedCallbacks[x] = new FixedChainStaticTargetInterceptor( @@ -342,16 +340,15 @@ class CglibAopProxy implements AopProxy, Serializable { */ private static Object processReturnType(Object proxy, Object target, Method method, Object retVal) { // Massage return value if necessary - if (retVal != null && retVal == target && - !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) { - // Special case: it returned "this". - // Note that we can't help if the target sets a reference - // to itself in another returned object. + if (retVal != null && retVal == target && !RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) { + // Special case: it returned "this". Note that we can't help + // if the target sets a reference to itself in another returned object. retVal = proxy; } Class returnType = method.getReturnType(); if (retVal == null && returnType != Void.TYPE && returnType.isPrimitive()) { - throw new AopInvocationException("Null return value from advice does not match primitive return type for: " + method); + throw new AopInvocationException( + "Null return value from advice does not match primitive return type for: " + method); } return retVal; } @@ -864,7 +861,7 @@ class CglibAopProxy implements AopProxy, Serializable { @Override public boolean equals(Object other) { - if (other == this) { + if (this == other) { return true; } if (!(other instanceof ProxyCallbackFilter)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ObjenesisCglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/ObjenesisCglibAopProxy.java index d7bdf7896a0..1d50e41b107 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ObjenesisCglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ObjenesisCglibAopProxy.java @@ -16,9 +16,9 @@ package org.springframework.aop.framework; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; @@ -54,15 +54,14 @@ class ObjenesisCglibAopProxy extends CglibAopProxy { @SuppressWarnings("unchecked") protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) { try { - Factory factory = (Factory) objenesis.newInstance(enhancer.createClass()); + Factory factory = (Factory) this.objenesis.newInstance(enhancer.createClass()); factory.setCallbacks(callbacks); return factory; } catch (ObjenesisException ex) { - // Fallback to Cglib on unsupported JVMs + // Fallback to regular proxy construction on unsupported JVMs if (logger.isDebugEnabled()) { - logger.debug("Unable to instantiate proxy using Objenesis, falling back " - + "to regular proxy construction", ex); + logger.debug("Unable to instantiate proxy using Objenesis, falling back to regular proxy construction", ex); } return super.createProxyClassAndInstance(enhancer, callbacks); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java index ed60145424f..7db7d8272c3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java @@ -64,7 +64,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo * @see #setPatterns */ public void setPattern(String pattern) { - setPatterns(new String[] {pattern}); + setPatterns(pattern); } /** @@ -72,7 +72,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo * Matching will be the union of all these; if any match, * the pointcut matches. */ - public void setPatterns(String[] patterns) { + public void setPatterns(String... patterns) { Assert.notEmpty(patterns, "'patterns' must not be empty"); this.patterns = new String[patterns.length]; for (int i = 0; i < patterns.length; i++) { @@ -94,7 +94,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo * @see #setExcludedPatterns */ public void setExcludedPattern(String excludedPattern) { - setExcludedPatterns(new String[] {excludedPattern}); + setExcludedPatterns(excludedPattern); } /** @@ -102,7 +102,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo * Matching will be the union of all these; if any match, * the pointcut matches. */ - public void setExcludedPatterns(String[] excludedPatterns) { + public void setExcludedPatterns(String... excludedPatterns) { Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty"); this.excludedPatterns = new String[excludedPatterns.length]; for (int i = 0; i < excludedPatterns.length; i++) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java index 4d2747c1489..fd78bfd6048 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -180,7 +180,6 @@ public class ComposablePointcut implements Pointcut, Serializable { return this.methodMatcher; } - @Override public boolean equals(Object other) { if (this == other) { @@ -189,7 +188,6 @@ public class ComposablePointcut implements Pointcut, Serializable { if (!(other instanceof ComposablePointcut)) { return false; } - ComposablePointcut that = (ComposablePointcut) other; return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) && ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher); @@ -209,8 +207,7 @@ public class ComposablePointcut implements Pointcut, Serializable { @Override public String toString() { - return "ComposablePointcut: ClassFilter [" + this.classFilter + - "], MethodMatcher [" + this.methodMatcher + "]"; + return "ComposablePointcut: " + this.classFilter + ", " +this.methodMatcher; } }