Skip to content

AbstractMockHttpServletRequestBuilder#param does not allow null#36599

Open
seregamorph wants to merge 1 commit intospring-projects:mainfrom
seregamorph:AbstractMockHttpServletRequestBuilder-param-nullable
Open

AbstractMockHttpServletRequestBuilder#param does not allow null#36599
seregamorph wants to merge 1 commit intospring-projects:mainfrom
seregamorph:AbstractMockHttpServletRequestBuilder-param-nullable

Conversation

@seregamorph
Copy link
Copy Markdown

@seregamorph seregamorph commented Apr 5, 2026

Problem statement

Since Spring Framework 7.0 it's not possible to use null value as an argument for MockMvc query parameters.
E.g. for such snippet of Kotlin code

mockMvc
    .perform(
        get("/url")
            .param("limit", "1"),
            .param("cursor", null) // <- compilation fails now
    ).andExpect(status().isOk)

While null value is a legal value for query parameters (it's serialized as "?paramName" in the query string without following = (and is expected in our test on the server side)

Original change: bc5d771 by @sdeleuze

Proposed solution

Mark argument @Nullable for Java callers and Kotlin extension.

Signed-off-by: seregamorph <serega.morph@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 5, 2026
@sdeleuze sdeleuze changed the title Kotlin: AbstractMockHttpServletRequestBuilder.param does not allow null AbstractMockHttpServletRequestBuilder#param does not allow null Apr 5, 2026
@sdeleuze
Copy link
Copy Markdown
Contributor

sdeleuze commented Apr 5, 2026

@seregamorph If we do this change, we are going to need to update the nullability in much more other places (fields, UriComponentsBuilder, etc.)

@rstoyanchev Could you please confirm query parameters value should be nullable?

@sdeleuze sdeleuze self-assigned this Apr 5, 2026
@sdeleuze sdeleuze added the in: test Issues in the test module label Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: test Issues in the test module status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants