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

Refine *HttpMessageConverter#getContentLength return value null safety #32325

Closed
DamonChen117 opened this issue Feb 24, 2024 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Milestone

Comments

@DamonChen117
Copy link

id("org.springframework.boot") version "2.3.9.RELEASE"

I need to extend MappingJackson2HttpMessageConverter and override getContentLength

  1. If the return type is Long?, it will not compile
    override
    fun getContentLength(obj:Any, contentType:MediaType?) : Long?

Compile error:
Return type of 'getContentLength' is not a subtype of the return type of the overridden member 'protected/protected and package/ open fun getContentLength(p0: Any, @nullable p1: MediaType?): Long defined in org.springframework.http.converter.json.MappingJackson2HttpMessageConverter'

  1. If the return type is Long, it will get NullPointException at runtime.
    override
    fun getContentLength(obj:Any, contentType:MediaType?) : Long

  2. In AbstractJackson2HttpMessageConverter the return is not Nullable
    @OverRide
    protected Long getContentLength(Object object, @nullable MediaType contentType)

  3. In AbstractHttpMessageConverter the return is Nullable
    @nullable
    protected Long getContentLength(T t, @nullable MediaType contentType)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 24, 2024
@sdeleuze sdeleuze added the theme: kotlin An issue related to Kotlin support label Feb 24, 2024
@sdeleuze sdeleuze self-assigned this Feb 24, 2024
@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 27, 2024
@sdeleuze sdeleuze added this to the 6.1.5 milestone Feb 27, 2024
@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 27, 2024

Looks like AbstractJackson2HttpMessageConverter#getContentLength nullability needs to be refined indeed, as well as ResourceHttpMessageConverter#getContentLength one.

@sdeleuze sdeleuze changed the title override nullable return type getContentLength MappingJackson2HttpMessageConverter in Kotlin Make MappingJackson2HttpMessageConverter#getContentLength return value nullable Feb 27, 2024
@sdeleuze sdeleuze changed the title Make MappingJackson2HttpMessageConverter#getContentLength return value nullable Refine *HttpMessageConverter#getContentLength return value null safety Feb 27, 2024
@sdeleuze sdeleuze added for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x labels Feb 27, 2024
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x labels Feb 27, 2024
@github-actions github-actions bot removed the for: backport-to-6.0.x Marks an issue as a candidate for backport to 6.0.x label Feb 27, 2024
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Mar 12, 2024
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 theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants