Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15541

Leveraging kotlin-reflect to determine interface method parameters

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 5.0 RC4
    • Component/s: None
    • Labels:
    • Last commented by a User:
      true

      Description

      Following up from https://jira.spring.io/browse/DATAJPA-1118 :

      In web-mvc I can declare a method where the parameter name is automatically picked up:

      @GetMapping fun foo(@RequestParam bar: String): Any { ... }
      

      When I try to create a custom method with arguments in a spring-data-jpa repository interface it doesn't work with the following message:

      IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8.

      It would be convenient If this also worked without having to specify @Param("name").

      I'm using Kotlin 1.1 on JDK8 with no special compilation options.

        Issue Links

          Activity

          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          Even on Java 8, user code has to be compiled with -parameters for this to actually work with interface methods, since debug symbols (our fallback code path) are only stored for concrete methods (with method bodies). I guess there might be a similar flag with the Kotlin compiler?

          Show
          juergen.hoeller Juergen Hoeller added a comment - Even on Java 8, user code has to be compiled with -parameters for this to actually work with interface methods, since debug symbols (our fallback code path) are only stored for concrete methods (with method bodies). I guess there might be a similar flag with the Kotlin compiler?
          Hide
          cleiter Christoph Leiter added a comment -

          Kotlin 1.1 introduced a new feature: https://kotlinlang.org/docs/reference/whatsnew11.html#parameter-names-in-the-bytecode

          Kotlin now supports storing parameter names in the bytecode. This can be enabled using the -java-parameters command line option.

          I can try whether this option helps, I wasn't aware that debug symbols are not working for interface argument names.

          Show
          cleiter Christoph Leiter added a comment - Kotlin 1.1 introduced a new feature: https://kotlinlang.org/docs/reference/whatsnew11.html#parameter-names-in-the-bytecode Kotlin now supports storing parameter names in the bytecode. This can be enabled using the -java-parameters command line option. I can try whether this option helps, I wasn't aware that debug symbols are not working for interface argument names.
          Hide
          sdeleuze Sébastien Deleuze added a comment - - edited

          My hope is that could be available by default in Kotlin without a compiler flag by leveraging kotlin-reflect, but I am not sure yet about that. I will do a quick check shortly.

          Show
          sdeleuze Sébastien Deleuze added a comment - - edited My hope is that could be available by default in Kotlin without a compiler flag by leveraging kotlin-reflect , but I am not sure yet about that. I will do a quick check shortly.
          Hide
          sdeleuze Sébastien Deleuze added a comment -

          Fixed via a dedicated KotlinReflectionParameterNameDiscoverer, see this commit for more details.

          Show
          sdeleuze Sébastien Deleuze added a comment - Fixed via a dedicated KotlinReflectionParameterNameDiscoverer , see this commit for more details.

            People

            • Assignee:
              sdeleuze Sébastien Deleuze
              Reporter:
              cleiter Christoph Leiter
              Last updater:
              Stéphane Nicoll
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 weeks, 3 days ago