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

Wrong type inference in Kotlin while overriding RequestMappingHandlerMapping#getMappingForMethod #25657

Closed
pavelshackih opened this issue Aug 28, 2020 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@pavelshackih
Copy link

Hi!

Im trying override method org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping#getMappingForMethod in Kotlin:

class CustomVersionRequestMappingHandlerMapping : RequestMappingHandlerMapping() {

    override fun getMappingForMethod(method: Method, handlerType: Class<*>): RequestMappingInfo {
        ...
    }

And kotlin compiler inference return type as non-nullable, but base abstract method in org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping#getMappingForMethod declared as nullable:

@Nullable
protected abstract T getMappingForMethod(Method method, Class<?> handlerType);

So if I try change return type as nullable:

override fun getMappingForMethod(method: Method, handlerType: Class<*>): RequestMappingInfo? {

compiler fails with error:

Return type is 'RequestMappingInfo?', which is not a subtype of overridden protected/protected and package/ open fun getMappingForMethod(method: Method, handlerType: Class<*>): RequestMappingInfo defined in org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping

It seems like Kotlin applies nullability rules from package-info file in this case:

@NonNullApi
@NonNullFields
package org.springframework.web.reactive.result.method.annotation;

and it is bug.

How can I fixed that?

Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 28, 2020
@sbrannen
Copy link
Member

@sdeleuze, thoughts?

@sdeleuze
Copy link
Contributor

Indeed we miss the @Nullable in the override of the Reactive version (on Spring MVC side it is present), I will fix this.

@sdeleuze sdeleuze self-assigned this Sep 25, 2020
@sdeleuze sdeleuze added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 25, 2020
@sdeleuze sdeleuze added this to the 5.2.10 milestone Sep 25, 2020
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Sep 25, 2020
@spring-projects-issues spring-projects-issues added the status: backported An issue that has been backported to maintenance branches label Sep 25, 2020
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Sep 25, 2020
zx20110729 pushed a commit to zx20110729/spring-framework that referenced this issue Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants