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.

Comment From: sbrannen

@sdeleuze, thoughts?

Comment From: sdeleuze

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