Browse Source

Deprecate ClassUtils.isCglibProxy methods in favor of AOP-level checks

Closes gh-22706
pull/22715/head
Juergen Hoeller 7 years ago
parent
commit
57de2e0900
  1. 4
      spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
  2. 9
      spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java
  3. 6
      spring-core/src/main/java/org/springframework/util/ClassUtils.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@ -166,7 +166,7 @@ class CglibAopProxy implements AopProxy, Serializable {
Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy"); Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy");
Class<?> proxySuperClass = rootClass; Class<?> proxySuperClass = rootClass;
if (ClassUtils.isCglibProxyClass(rootClass)) { if (rootClass.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) {
proxySuperClass = rootClass.getSuperclass(); proxySuperClass = rootClass.getSuperclass();
Class<?>[] additionalInterfaces = rootClass.getInterfaces(); Class<?>[] additionalInterfaces = rootClass.getInterfaces();
for (Class<?> additionalInterface : additionalInterfaces) { for (Class<?> additionalInterface : additionalInterfaces) {

9
spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@ -66,8 +66,8 @@ public abstract class AopUtils {
* @see #isCglibProxy * @see #isCglibProxy
*/ */
public static boolean isAopProxy(@Nullable Object object) { public static boolean isAopProxy(@Nullable Object object) {
return (object instanceof SpringProxy && return (object instanceof SpringProxy && (Proxy.isProxyClass(object.getClass()) ||
(Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass()))); object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)));
} }
/** /**
@ -91,7 +91,8 @@ public abstract class AopUtils {
* @see ClassUtils#isCglibProxy(Object) * @see ClassUtils#isCglibProxy(Object)
*/ */
public static boolean isCglibProxy(@Nullable Object object) { public static boolean isCglibProxy(@Nullable Object object) {
return (object instanceof SpringProxy && ClassUtils.isCglibProxy(object)); return (object instanceof SpringProxy &&
object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));
} }
/** /**

6
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -841,7 +841,9 @@ public abstract class ClassUtils {
* @param object the object to check * @param object the object to check
* @see #isCglibProxyClass(Class) * @see #isCglibProxyClass(Class)
* @see org.springframework.aop.support.AopUtils#isCglibProxy(Object) * @see org.springframework.aop.support.AopUtils#isCglibProxy(Object)
* @deprecated as of 5.2, in favor of custom (possibly narrower) checks
*/ */
@Deprecated
public static boolean isCglibProxy(Object object) { public static boolean isCglibProxy(Object object) {
return isCglibProxyClass(object.getClass()); return isCglibProxyClass(object.getClass());
} }
@ -850,7 +852,9 @@ public abstract class ClassUtils {
* Check whether the specified class is a CGLIB-generated class. * Check whether the specified class is a CGLIB-generated class.
* @param clazz the class to check * @param clazz the class to check
* @see #isCglibProxyClassName(String) * @see #isCglibProxyClassName(String)
* @deprecated as of 5.2, in favor of custom (possibly narrower) checks
*/ */
@Deprecated
public static boolean isCglibProxyClass(@Nullable Class<?> clazz) { public static boolean isCglibProxyClass(@Nullable Class<?> clazz) {
return (clazz != null && isCglibProxyClassName(clazz.getName())); return (clazz != null && isCglibProxyClassName(clazz.getName()));
} }
@ -858,7 +862,9 @@ public abstract class ClassUtils {
/** /**
* Check whether the specified class name is a CGLIB-generated class. * Check whether the specified class name is a CGLIB-generated class.
* @param className the class name to check * @param className the class name to check
* @deprecated as of 5.2, in favor of custom (possibly narrower) checks
*/ */
@Deprecated
public static boolean isCglibProxyClassName(@Nullable String className) { public static boolean isCglibProxyClassName(@Nullable String className) {
return (className != null && className.contains(CGLIB_CLASS_SEPARATOR)); return (className != null && className.contains(CGLIB_CLASS_SEPARATOR));
} }

Loading…
Cancel
Save