Skip to content

Commit 05d767b

Browse files
committed
Always propagate checked exceptions from Kotlin code behind CGLIB proxies
Closes gh-23844
1 parent 3065555 commit 05d767b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.cglib.proxy.MethodInterceptor;
5050
import org.springframework.cglib.proxy.MethodProxy;
5151
import org.springframework.cglib.proxy.NoOp;
52+
import org.springframework.core.KotlinDetector;
5253
import org.springframework.core.SmartClassLoader;
5354
import org.springframework.lang.Nullable;
5455
import org.springframework.util.Assert;
@@ -752,10 +753,17 @@ public Object proceed() throws Throwable {
752753
throw ex;
753754
}
754755
catch (Exception ex) {
755-
if (ReflectionUtils.declaresException(getMethod(), ex.getClass())) {
756+
if (ReflectionUtils.declaresException(getMethod(), ex.getClass()) ||
757+
KotlinDetector.isKotlinType(getMethod().getDeclaringClass())) {
758+
// Propagate original exception if declared on the target method
759+
// (with callers expecting it). Always propagate it for Kotlin code
760+
// since checked exceptions do not have to be explicitly declared there.
756761
throw ex;
757762
}
758763
else {
764+
// Checked exception thrown in the interceptor but not declared on the
765+
// target method signature -> apply an UndeclaredThrowableException,
766+
// aligned with standard JDK dynamic proxy behavior.
759767
throw new UndeclaredThrowableException(ex);
760768
}
761769
}

0 commit comments

Comments
 (0)