- What language is this for?
Java - Which rule?
S2201 - Why do you believe it’s a false-positive?
I often use the Optional.orElseThrow() method to validate a object - Are you using
- SonarLint 3.15.1
- VSCode 1.75.1
- How can we reproduce the problem? Give us a self-contained snippet (best) or screenshot (good)
Minimal setup:
Optional.empty().orElseThrow(() -> new Exeption()); // FP
Real world example:
// check unused inputs
for (String input : getInputSchema().keySet()) {
propertyJoints.stream()
.filter(joint -> joint.getPreviousTaskId().equals(SubTaskId.INPUT))
.filter(joint -> joint.getPreviousProperty().equals(input))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("Input property " + input + " is unused")); // FP
}