From 57de2e09008e0bd80683df63b40f0748945e83aa Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 29 Mar 2019 11:12:49 +0100 Subject: [PATCH] Deprecate ClassUtils.isCglibProxy methods in favor of AOP-level checks Closes gh-22706 --- .../org/springframework/aop/framework/CglibAopProxy.java | 4 ++-- .../java/org/springframework/aop/support/AopUtils.java | 9 +++++---- .../main/java/org/springframework/util/ClassUtils.java | 6 ++++++ 3 files changed, 13 insertions(+), 6 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 b14e26724bb..498513e122e 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 @@ -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"); * 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"); Class proxySuperClass = rootClass; - if (ClassUtils.isCglibProxyClass(rootClass)) { + if (rootClass.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) { proxySuperClass = rootClass.getSuperclass(); Class[] additionalInterfaces = rootClass.getInterfaces(); for (Class additionalInterface : additionalInterfaces) { 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 6a6462c9e97..8055ec98cb6 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 @@ -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"); * you may not use this file except in compliance with the License. @@ -66,8 +66,8 @@ public abstract class AopUtils { * @see #isCglibProxy */ public static boolean isAopProxy(@Nullable Object object) { - return (object instanceof SpringProxy && - (Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass()))); + return (object instanceof SpringProxy && (Proxy.isProxyClass(object.getClass()) || + object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR))); } /** @@ -91,7 +91,8 @@ public abstract class AopUtils { * @see ClassUtils#isCglibProxy(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)); } /** diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index c1242082520..91cd74ac3a1 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -841,7 +841,9 @@ public abstract class ClassUtils { * @param object the object to check * @see #isCglibProxyClass(Class) * @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) { return isCglibProxyClass(object.getClass()); } @@ -850,7 +852,9 @@ public abstract class ClassUtils { * Check whether the specified class is a CGLIB-generated class. * @param clazz the class to check * @see #isCglibProxyClassName(String) + * @deprecated as of 5.2, in favor of custom (possibly narrower) checks */ + @Deprecated public static boolean isCglibProxyClass(@Nullable Class clazz) { 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. * @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) { return (className != null && className.contains(CGLIB_CLASS_SEPARATOR)); }