How is Optional.orElse(null)
marked with org.jetbrains.annotations.NotNull
The javadoc of orElse
explicitly states that null is allowed
* @param other the value to be returned, if no value is present.
* May be {@code null}.
But my code flags a "bug" in SonarQube.
return users.findById(userID)
.flatMap(user -> students.findByUser(user))
.map(GetAllStudentsSvc::mapToStudent)
.orElse(null);
Looking at the code it doesn't appear to be marked. Looking at the IDE it also does not appear to be marked
Even annotating the code as @Nullable
does not help.
I think it is clear that null
is perfectly fine here, so I's suggest to suppress it. This worked for me:
@SuppressWarnings("squid:S2637")