Skip to content

JSpecifyMode: function returning a @Nullable is incorrectly handled #1671

Description

@nvervelle

Hello, it's probably related to #1532 , but as I'm not entirely sure, I prefer to open a dedicated issue (feel free to close it if it's the same underlying problem).

I've tried activating JSpecifyMode in my project and I encounter the following false positive

    return webClient
        .post()
        .uri(properties.accessUrl())
        .contentType(MediaType.APPLICATION_FORM_URLENCODED)
        .body(BodyInserters.fromFormData(formData))
        .retrieve()
        .toEntity(JsonNode.class)
        .mapNotNull(ResponseEntity::getBody)
        .mapNotNull(this::updateAccessToken)
        .switchIfEmpty(Mono.error(() -> new IllegalStateException("Unable to get access token")));

The error message is

error: [NullAway] referenced method returns @Nullable, but functional interface method java.util.function.Function.apply(T) returns @NonNull
          .mapNotNull(ResponseEntity::getBody)

but ResponseEntity.getBody() (from org.springframework.http.ResponseEntity) is defined as

  public @Nullable T getBody() {
    return this.body;
  }

and Mono.mapNotNull() is defined as

  public final <R> Mono<R> mapNotNull(Function <? super T, ? extends @Nullable R> mapper) {
    ...
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions