Skip to content

Commit 1fd447f

Browse files
authored
Reduce String garbage in CglibAopProxy.doValidateClass()
Closes gh-24672
1 parent 3cbea86 commit 1fd447f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,24 @@ private void validateClassIfNecessary(Class<?> proxySuperClass, @Nullable ClassL
253253
*/
254254
private void doValidateClass(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
255255
if (proxySuperClass != Object.class) {
256+
final boolean infoEnabled = logger.isInfoEnabled();
257+
final boolean debugEnabled = logger.isDebugEnabled();
256258
Method[] methods = proxySuperClass.getDeclaredMethods();
257259
for (Method method : methods) {
258260
int mod = method.getModifiers();
259261
if (!Modifier.isStatic(mod) && !Modifier.isPrivate(mod)) {
260262
if (Modifier.isFinal(mod)) {
261-
if (implementsInterface(method, ifcs)) {
263+
if (infoEnabled && implementsInterface(method, ifcs)) {
262264
logger.info("Unable to proxy interface-implementing method [" + method + "] because " +
263265
"it is marked as final: Consider using interface-based JDK proxies instead!");
264266
}
265-
logger.debug("Final method [" + method + "] cannot get proxied via CGLIB: " +
266-
"Calls to this method will NOT be routed to the target instance and " +
267-
"might lead to NPEs against uninitialized fields in the proxy instance.");
267+
if (debugEnabled) {
268+
logger.debug("Final method [" + method + "] cannot get proxied via CGLIB: " +
269+
"Calls to this method will NOT be routed to the target instance and " +
270+
"might lead to NPEs against uninitialized fields in the proxy instance.");
271+
}
268272
}
269-
else if (!Modifier.isPublic(mod) && !Modifier.isProtected(mod) &&
273+
else if (debugEnabled && !Modifier.isPublic(mod) && !Modifier.isProtected(mod) &&
270274
proxyClassLoader != null && proxySuperClass.getClassLoader() != proxyClassLoader) {
271275
logger.debug("Method [" + method + "] is package-visible across different ClassLoaders " +
272276
"and cannot get proxied via CGLIB: Declare this method as public or protected " +
@@ -526,7 +530,7 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
526530
private static class StaticDispatcher implements Dispatcher, Serializable {
527531

528532
@Nullable
529-
private Object target;
533+
private final Object target;
530534

531535
public StaticDispatcher(@Nullable Object target) {
532536
this.target = target;
@@ -552,7 +556,7 @@ public AdvisedDispatcher(AdvisedSupport advised) {
552556
}
553557

554558
@Override
555-
public Object loadObject() throws Exception {
559+
public Object loadObject() {
556560
return this.advised;
557561
}
558562
}
@@ -959,11 +963,11 @@ public boolean equals(@Nullable Object other) {
959963
return true;
960964
}
961965

962-
private boolean equalsAdviceClasses(Advisor a, Advisor b) {
966+
private static boolean equalsAdviceClasses(Advisor a, Advisor b) {
963967
return (a.getAdvice().getClass() == b.getAdvice().getClass());
964968
}
965969

966-
private boolean equalsPointcuts(Advisor a, Advisor b) {
970+
private static boolean equalsPointcuts(Advisor a, Advisor b) {
967971
// If only one of the advisor (but not both) is PointcutAdvisor, then it is a mismatch.
968972
// Takes care of the situations where an IntroductionAdvisor is used (see SPR-3959).
969973
return (!(a instanceof PointcutAdvisor) ||

0 commit comments

Comments
 (0)