Skip to content

Kotlin method parameter names are not included in bytecode #12640

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
ruifigueira opened this issue Mar 26, 2018 · 1 comment
Closed

Kotlin method parameter names are not included in bytecode #12640

ruifigueira opened this issue Mar 26, 2018 · 1 comment
Labels
status: superseded An issue that has been superseded by another

Comments

@ruifigueira
Copy link
Contributor

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>
@philwebb
Copy link
Member

Thanks for the detailed report. I'll close this one in favor of the PR that you raised (#12641).

@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2018
@philwebb philwebb added status: superseded An issue that has been superseded by another and removed status: duplicate A duplicate of another issue labels Sep 11, 2018
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants