Skip to content

Customizer null checks in HTTP client builders assert the wrong attribute - #51509

Merged
snicoll merged 2 commits into
spring-projects:4.0.xfrom
kdomo:fix-http-client-assert
Aug 30, 2026
Merged

Customizer null checks in HTTP client builders assert the wrong attribute#51509
snicoll merged 2 commits into
spring-projects:4.0.xfrom
kdomo:fix-http-client-assert

Conversation

@kdomo

@kdomo kdomo commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

AbstractClientHttpRequestFactoryBuilder.mergedCustomizers(Consumer<T>) and its reactive counterpart assert on the customizers field instead of the customizer parameter:

protected final List<Consumer<T>> mergedCustomizers(Consumer<T> customizer) {
    Assert.notNull(this.customizers, "'customizer' must not be null");
    return merge(this.customizers, List.of(customizer));
}

The field can never be null because the constructor defaults it to an empty list, so the assertion always passes and a null customizer is not rejected. Callers get an NPE from List.of(customizer) on the next line rather than the intended IllegalArgumentException. The mergedCustomizers(Collection<Consumer<T>>) overload just below does check its parameter.

This affects withCustomizer(...) on all builders that extend these two base classes.

The same commit also corrects two Assert messages that name a parameter which doesn't exist on the method:

  • ClientHttpConnectorBuilder.of(Class<T> clientHttpConnectorType) reports 'requestFactoryType', which looks like a leftover from ClientHttpRequestFactoryBuilder.of. The Assert.isTrue on the following line already uses the correct name.
  • HttpComponentsClientHttpConnectorBuilder.withHttpClientCustomizer(Consumer<HttpAsyncClientBuilder> httpClientCustomizer) reports 'customizer', while withConnectionManagerCustomizer and withConnectionConfigCustomizer in the same class both use their parameter names.

I've added tests for the null checks. There's no test class for the ClientHttpConnectorBuilder interface, so the of message change isn't covered — happy to add one if you'd prefer.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 30, 2026
@kdomo
kdomo force-pushed the fix-http-client-assert branch from ca1c303 to 755c393 Compare August 30, 2026 05:44
kdomo and others added 2 commits August 30, 2026 20:16
AbstractClientHttpRequestFactoryBuilder.mergedCustomizers and its
reactive counterpart asserted on the customizers field rather than
the customizer parameter. The field is never null since the
constructor defaults it to an empty list, so the assertion always
passed and a null customizer was not rejected.

See spring-projectsgh-51509

Signed-off-by: kdomo <dongho5088@naver.com>
@snicoll
snicoll force-pushed the fix-http-client-assert branch from 755c393 to 60445a5 Compare August 30, 2026 18:26
@snicoll
snicoll changed the base branch from main to 4.0.x August 30, 2026 18:26
@snicoll snicoll changed the title Fix null checks and Assert messages in HTTP client builders Customizer null checks in HTTP client builders assert the wrong attribute Aug 30, 2026
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 30, 2026
@snicoll snicoll added this to the 4.0.9 milestone Aug 30, 2026
@snicoll
snicoll merged commit f0e7cd9 into spring-projects:4.0.x Aug 30, 2026
3 of 4 checks passed
@snicoll

snicoll commented Aug 30, 2026

Copy link
Copy Markdown
Member

Thanks. The tests should have been put on the base class for consistency. In doing so I've noticed one more place where that check isn't consistent. I have also removed the update of assertion in the two other locations that are unrelated.

See 60445a5

@snicoll snicoll self-assigned this Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants