-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
NullPointerException
with @RequestMapping
on Kotlin property accessors
#31856
Comments
@bclozel could you please transfer this one to the Framework issue tracker. |
Thanks for the detailed explanation but there's no added value in us replicating that sample from the steps you've described. Our time would be better spent looking at the final example as you see it and understand what could be the issue. Can you please first upgrade your sample to use Spring Framework |
I do not understand your problem as the "final example" is in the issue description - just copy and paste! Anyway, here are the zips (Same problem with 3.2.1-SNAPSHOT) |
I don't have a problem. You're making it sound way simpler than it often is. If you have the repro as a small sample, describing the steps to get to there is really a bad idea as a step might be missing or misleading and we'd end up in a back and forth trying to figure out the missing bit, and that's frustrating for everybody. As I've already explained, I suppose we can both agree you prefer us investigating the actual problem rather than spending time rebuilding the pieces to reproduce it. |
I am not a kotlin expert but what is the purpose of that val index: String
@GetMapping("/")
get() = "Greetings from Spring Boot!"
|
Kotlin's val index: String @GetMapping("/") get() = "Greetings from Spring Boot!" produces something like Java's @GetMapping("/") String getIndex() { return "Greetings from Spring Boot!"; } See the last paragraph of my initial issue description for an error analysis. I think a Kotlin expert is needed here. |
Here is a patch for the issue (for spring-framework main): |
@RequestMapping
on Kotlin property accessors
@RequestMapping
on Kotlin property accessorsNullPointerException
with @RequestMapping
on Kotlin property accessors
The variant in org.springframework.web.method.support in order to allow testing with a various classes. See spring-projectsgh-31856
There was 2 main approaches possible to solve this issue:
I chose the later because conceptually, those Kotlin property accessors translate into plain Java methods that we are unable to distinguish from regular Java methods unless Kotlin reflection is used. That also avoid to introduce an unnecessary performance overhead. I also chose to not introduce a dependency on Kotlin reflection in |
This commit adds support for Kotlin properties in Spring WebFlux controllers, supported for reasons explained in spring-projectsgh-31856, with kotlinx.serialization codecs. See spring-projectsgh-34284
This commit adds support for Kotlin properties in Spring WebMVC controllers, supported for reasons explained in spring-projectsgh-31856, with kotlinx.serialization converters. Closes spring-projectsgh-34284
I was able to reproduce the issue with one of spring-boots own examples. Following Getting Started > Building an Application with Spring Boot:
Rename HelloController.java to HelloController.kt and change it into:
Change build.gradle into:
Then run it with
./gradlew bootRun
:curl http://localhost:8080
:Removing runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect:1.9.21' from build.gradle resolves the issue:
$ ./gradlew bootRun $ curl http://localhost:8080 Greetings from Spring Boot!
So the problem appears only with kotlin-reflect on the (runtime) classpath.
This is queried in
org.springframework.web.method.support.InvocableHandlerMethod:246
and leads to an exception in
InvocableHandlerMethod:302
if the case.The JVM method
getIndex()
is not found in the list of Kotlin methods (equals()
etc.).The text was updated successfully, but these errors were encountered: