Skip to content

Fix Kotlin value class handling for suspending AOP methods - #37191

Open
dmitrysulman wants to merge 1 commit into
spring-projects:mainfrom
dmitrysulman:gh-37155
Open

Fix Kotlin value class handling for suspending AOP methods#37191
dmitrysulman wants to merge 1 commit into
spring-projects:mainfrom
dmitrysulman:gh-37155

Conversation

@dmitrysulman

@dmitrysulman dmitrysulman commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Fix handling of Kotlin value-class return values from proxied suspending functions.

When a suspending method completes through the direct path, Kotlin expects the unboxed representation of a value class. Spring AOP could return the boxed value produced by the interceptor chain instead, causing incorrect results and ClassCastExceptions.

This change unboxes applicable value-class results before returning them from JDK and CGLIB proxies and adds tests.

See the the detailed root-cause analysis: #37155 (comment).

Fixes #37155

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 22, 2026
@dmitrysulman
dmitrysulman force-pushed the gh-37155 branch 2 times, most recently from 71bd2a5 to 07c8ed1 Compare August 22, 2026 16:43
Unbox Kotlin value class results returned from proxied suspending methods before returning them to the caller.

Spring AOP interceptor chains expose return values as Object, which causes Kotlin value class results to be boxed. For suspending functions, the direct return path expects the unboxed value class representation.

Update both CglibAopProxy and JdkDynamicAopProxy to detect value class return types and unbox boxed results after coroutine adaptation.

Add tests for suspending methods returning value classes.

See spring-projects#37155

Signed-off-by: Dmitry Sulman <dmitry.sulman@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AOP-proxied Kotlin suspending function returning kotlin.Result intermittently double-wraps the return value under concurrency (ClassCastException)

2 participants