Skip to content

Add AOT support for Kotlin constructors with optional parameters #29820

Closed
@DarkAtra

Description

@DarkAtra

Take the following kotlin @Service:

@Service
class Service(
    private val applicationContext: ApplicationContext,
    private val client: Client = Client()
)

When running on JVM the code behaves as expected: only the constructor parameter without a default value is autowired.
When running the native image the application does not start and throws the following exception indicating that spring
attempts to autowire all constructor parameters (even the one with a default value):

java.lang.NullPointerException: Parameter specified as non-null is null: method de.darkatra.kotlindiissue.Service.<init>, parameter client

Reproducer with details: https://github.com/DarkAtra/spring-native-kotlin-di-issue
Affected Spring Framework versions: 6.0.2, 6.0.3, 6.0.4 (verified by building the current spring-boot main branch locally)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingtheme: kotlinAn issue related to Kotlin supporttype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions