Skip to content

CoroutineUtils assumes Kotlin value class has an accessible constructor #32573

Closed as not planned
@cloudshiftchris

Description

Affects: Spring Framework 6.1.x / Spring Boot 3.2.x

With Spring Boot 3.1.x (Spring Framework 6.0.x) proxies around Kotlin suspending functions that took a value class were able to handle value class arguments that did not have an accessible constructor, such as:

@JvmInline
public value class TenantCode private constructor(private val codeStr: String) {
    init {
        require(codeRegex.matches(codeStr)) { "Tenant code '$codeStr' must match regex $codeRegex" }
        require(codeStr.length >= 3) { "Tenant code must be >= 3 characters" }
    }

    public companion object {
        private val codeRegex = Regex("[0-9a-z-]+")

        public fun of(code: String): TenantCode {
            return TenantCode(code)
        }
    }

    override fun toString(): String = codeStr
}

Spring 6.1.x, in #32324, refactored CoroutineUtils to require an accessible primary constructor, failing with an IllegalAccessException if the constructor is not accessible.

As a workaround have disabled (currently unneeded) proxying of these interfaces (@repository), in preference to weakening the value class encapsulation.

This broke during a Spring Boot 3.1.5 -> 3.2.4 upgrade.

Its also not clear why instantiation is required, as the argument value already exists and is of the same type - is there perhaps a performance impact here as well?

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: duplicateA duplicate of another issuetheme: kotlinAn issue related to Kotlin support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions