Skip to content

Non-null nullable Kotlin value class parameters in RestControllers crash with IllegalArgumentException #36710

Closed as duplicate

Description

@xcq1

I'm seeing issues with optional Kotlin value classes no longer working correctly in RestControllers after updating:
Spring Boot 3.5.13→3.5.14 (Framework 6.2.17→6.2.18)
Spring Boot 4.0.5→4.0.6 (Framework 7.0.6→7.0.7)

After debugging a bit, this only occurs if both the parameter type is a nullable Kotlin value class and it receives a non-null argument, the other combinations seem to work fine.
To reproduce, create a new Kotlin Spring Boot project and add this RestController:

package org.example.springsandbox

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class TestController {
    @JvmInline
    value class TestId(val id: String)

    @GetMapping("/test")
    fun test(arg: TestId?) = "Hello $arg!"
}

Behavior before the update:

$ curl 'localhost:8080/test'
Hello null!%
$ curl 'localhost:8080/test?arg=World'
Hello TestId(id=World)!%

Behavior after the update:

$ curl 'localhost:8080/test'
Hello null!%
$ curl 'localhost:8080/test?arg=World'
{"timestamp":"2026-04-27T09:29:32.648Z","status":500,"error":"Internal Server Error","path":"/test"}%

Stacktrace in the running application console:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.IllegalStateException: object is not an instance of declaring class
Handler [org.example.springsandbox.TestController]
Method [public java.lang.String org.example.springsandbox.TestController.test-3e-eavU(java.lang.String)] with argument values:
[0] [type=java.lang.String] [value=World]] with root cause

java.lang.IllegalArgumentException: object is not an instance of declaring class
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.checkReceiver(DirectMethodHandleAccessor.java:197) ~[na:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:99) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
	at kotlin.reflect.jvm.internal.calls.ValueClassAwareCaller.call(ValueClassAwareCaller.kt:200) ~[kotlin-reflect-2.2.21.jar:2.2.21-release-469]
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:250) ~[kotlin-reflect-2.2.21.jar:2.2.21-release-469]
	at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:155) ~[kotlin-reflect-2.2.21.jar:2.2.21-release-469]
	at org.springframework.web.method.support.InvocableHandlerMethod$KotlinDelegate.invokeFunction(InvocableHandlerMethod.java:330) ~[spring-web-7.0.7.jar:7.0.7]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:250) ~[spring-web-7.0.7.jar:7.0.7]

Activity

  1. added
    status: waiting-for-triage
    on Apr 27, 2026
  2. added
    in: web
    theme: kotlin
    on Apr 27, 2026
  3. bclozel commented on Apr 27, 2026

    @bclozel
    Member

    @xcq1 this looks like a duplicate of #36704 - can you confirm?

  4. added
    status: waiting-for-feedback
    on Apr 27, 2026
  5. self-assigned this
    on Apr 27, 2026
  6. xcq1 commented on Apr 27, 2026

    @xcq1
    Author

    @bclozel From the description it sounds like a similar root cause except with reactive instead of servlet stack and a slightly different exception.

  7. added
    status: feedback-provided
    and removed
    status: waiting-for-feedback
    on Apr 27, 2026
  8. sdeleuze commented on Apr 27, 2026

    @sdeleuze
    Contributor

    Yeah that's a regression caused by #36449 and a duplicate of #36665, I will try to fix it leveraging this PR so I close this issue.

  9. added
    status: superseded
    and removed
    status: waiting-for-triage
    status: feedback-provided
    on Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: supersededtheme: kotlin

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions