Closed
Description
I just had a similar issue to #11010. I declared an @Endpoint
kotlin class with a method with a @Selector
parameter, but the parameter name is "lost in compilation".
I noticed that, for Java classes, this is normally not an issue, because Spring Boot configures maven-compiler-plugin
to include parameter name information in bytecode (#9323), and we can definitely do the same for kotlin-maven-plugin
by providing a -java-parameters
argument in its configuration.
How to reproduce
- Add the following kotlin code into a standard Spring Boot project with maven (ensure you have
spring-boot-starter-tests
):
import org.assertj.core.api.Assertions.*
import org.junit.Test
import kotlin.reflect.jvm.javaMethod
class KotlincJavaParametersTest {
private fun say(hello: String, world: String) = "$hello $world"
@Test
fun testMethodParameterName() {
val javaMethod = ::say.javaMethod!!
val parameters = javaMethod.parameters
assertThat(parameters).isNotEmpty
assertThat(parameters.map { it.name }).containsExactly("hello", "world")
}
}
- Run it with
mvn clean test
How to fix
Kotlin compiler (kotlinc
) supports a -java-parameters
argument that was introduced in version 1.1 (https://kotlinlang.org/docs/reference/whatsnew11.html#parameter-names-in-the-bytecode):
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-java-parameters</arg>
</args>
</configuration>
</plugin>