Skip to content

NPE when passing null for optional parameter when invoking method. #543

@rnett

Description

@rnett

Describe the bug

I have code that looks like:

(invoker as RpcInvokator.Method<Any>).call(rpcImplementation, args)

For the RPC service method:

suspend fun getArtifactInfo(groupId: String, artifactId: String, repository: String = MAVEN_CENTRAL_URL): ArtifactInfo

running the code with args = [com.google.inject, guice, null] results in an NPE:

Caused by: java.lang.NullPointerException: null cannot be cast to non-null type kotlin.String

	at dev.rnett.mavenlibraries.MetadataTools$$rpcServiceStub$Companion$getArtifactInfoInvokator$1.call(MetadataTools.kt)
	at dev.rnett.mavenlibraries.MetadataTools$$rpcServiceStub$Companion$getArtifactInfoInvokator$1.call(MetadataTools.kt)

I have debugged the code and checked that the method spec's last parameter is indeed marked as optional.

This appears to be how methods with optional parameters are invoked by 1st party code, e.g. by CallableParametersSerializer.

To Reproduce
Steps to reproduce the behavior:
Kotlin version: 2.2.21
Gradle version: 9.2.1
OS (Or at least KMP platform): Windows, JVM

Expected behavior

A method with an optional parameter can be invoked in a way that uses the default for the parameter.
Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions