Skip to content

NPE in ClientRequest.attribute(name) when accessing null value [SPR-17486] #22018

Closed
@spring-projects-issues

Description

@spring-projects-issues

João Eiras opened SPR-17486 and commented

Hi.

I have the following code

webClient.get()
  .uri(b -> b.path("/endpoint").build())
  .attribute("x", null)
  .retrieve()
  .bodyToMono(String.class)
  .block();

I also have a exchangeFilter registered in the webClient which looks up attribute "x". When calling clientRequest.attribute("x") then I get a NPE.

java.lang.NullPointerException: null
  at java.util.Objects.requireNonNull(Objects.java:203)
  at java.util.Optional.<init>(Optional.java:96)
  at java.util.Optional.of(Optional.java:108)
  at org.springframework.web.reactive.function.client.ClientRequest.attribute(ClientRequest.java:81)

The solution in https://github.com/spring-projects/spring-framework/blob/master/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java#L88

default Optional<Object> attribute(String name) {
    return Optional.ofNullable(attributes().get(name));
}

Thank you.


Affects: 5.0.10, 5.1 GA

Referenced from: commits 5382260, 818c2aa, d96a7b4

Backported to: 5.0.11

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions