Skip to content
New issue

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

By clicking “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? Sign in to your account

Leveraging kotlin-reflect to determine interface method parameters [SPR-15541] #20100

Closed
spring-issuemaster opened this issue May 14, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented May 14, 2017

Christoph Leiter opened SPR-15541 and commented

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:

  • DATAJPA-1118 Automatically determine Kotlin parameter names in repository methods ("is depended on by")

Referenced from: commits 5ae35f6

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 15, 2017

Juergen Hoeller commented

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?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 15, 2017

Christoph Leiter commented

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 15, 2017

Sébastien Deleuze commented

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 6, 2017

Sébastien Deleuze commented

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.