Skip to content

Commit

Permalink
Document limitation of AopTestUtils.getUltimateTargetObject() regardi…
Browse files Browse the repository at this point in the history
…ng non-static TargetSource

Closes gh-29276
  • Loading branch information
sbrannen committed Oct 7, 2022
1 parent 8caed88 commit 5eee467
Showing 1 changed file with 9 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -43,6 +43,7 @@ public abstract class AopTestUtils {
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
* be returned; otherwise, the {@code candidate} will be returned
* <em>as is</em>.
* @param <T> the type of the target object
* @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null})
* @return the target object or the {@code candidate} (never {@code null})
Expand Down Expand Up @@ -75,11 +76,18 @@ public static <T> T getTargetObject(Object candidate) {
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
* nested proxies will be returned; otherwise, the {@code candidate}
* will be returned <em>as is</em>.
* <p>NOTE: If the top-level proxy or a nested proxy is not backed by a
* {@linkplain org.springframework.aop.TargetSource#isStatic() static}
* {@link org.springframework.aop.TargetSource TargetSource}, invocation of
* this utility method may result in undesired behavior such as infinite
* recursion leading to a {@link StackOverflowError}.
* @param <T> the type of the target object
* @param candidate the instance to check (potentially a Spring AOP proxy;
* never {@code null})
* @return the target object or the {@code candidate} (never {@code null})
* @throws IllegalStateException if an error occurs while unwrapping a proxy
* @see Advised#getTargetSource()
* @see org.springframework.aop.TargetSource#isStatic()
* @see org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass
*/
@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 5eee467

Please sign in to comment.