Skip to content

Commit 5eee467

Browse files
committed
Document limitation of AopTestUtils.getUltimateTargetObject() regarding non-static TargetSource
Closes gh-29276
1 parent 8caed88 commit 5eee467

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-test/src/main/java/org/springframework/test/util/AopTestUtils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ public abstract class AopTestUtils {
4343
* {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will
4444
* be returned; otherwise, the {@code candidate} will be returned
4545
* <em>as is</em>.
46+
* @param <T> the type of the target object
4647
* @param candidate the instance to check (potentially a Spring AOP proxy;
4748
* never {@code null})
4849
* @return the target object or the {@code candidate} (never {@code null})
@@ -75,11 +76,18 @@ public static <T> T getTargetObject(Object candidate) {
7576
* {@linkplain AopUtils#isAopProxy proxy}, the ultimate target of all
7677
* nested proxies will be returned; otherwise, the {@code candidate}
7778
* will be returned <em>as is</em>.
79+
* <p>NOTE: If the top-level proxy or a nested proxy is not backed by a
80+
* {@linkplain org.springframework.aop.TargetSource#isStatic() static}
81+
* {@link org.springframework.aop.TargetSource TargetSource}, invocation of
82+
* this utility method may result in undesired behavior such as infinite
83+
* recursion leading to a {@link StackOverflowError}.
84+
* @param <T> the type of the target object
7885
* @param candidate the instance to check (potentially a Spring AOP proxy;
7986
* never {@code null})
8087
* @return the target object or the {@code candidate} (never {@code null})
8188
* @throws IllegalStateException if an error occurs while unwrapping a proxy
8289
* @see Advised#getTargetSource()
90+
* @see org.springframework.aop.TargetSource#isStatic()
8391
* @see org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass
8492
*/
8593
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)