Optional.orElse(null) 用 org.jetbrains.annotations.NotNull 标记

Arc*_*ano 6 java sonarqube

如何Optional.orElse(null)标记为org.jetbrains.annotations.NotNull

javadocorElse明确指出允许 null

     * @param other the value to be returned, if no value is present.
     *        May be {@code null}.
Run Code Online (Sandbox Code Playgroud)

但我的代码在 SonarQube 中标记了一个“错误”。

        return users.findById(userID)
            .flatMap(user -> students.findByUser(user))
            .map(GetAllStudentsSvc::mapToStudent)
            .orElse(null);
Run Code Online (Sandbox Code Playgroud)

看代码好像没有标注。查看IDE,它似乎也没有被标记

在此输入图像描述

即使将代码注释为也@Nullable无济于事。

在此输入图像描述

Lan*_*dei 2

我认为很明显这null在这里完全没问题,所以我建议抑制它。这对我有用:

@SuppressWarnings("squid:S2637")