java:S3553 does not consider spring mvc optional parameters

I’m using Sonarqube 9.2 and have enabled rule:
java:S3553 “Optional” should not be used for parameters

Now I get a false positive for this code snippet in spring rest controllers:

ResponseEntity<Foo> getFoo(@PathVariable Long id, @RequestParam(value = "validation-scope") Optional<ValidationScope> validationScope, @RequestParam(value = "bar") Optional<UUID> bar) throws ValidationException;

Spring Framework documentation notes that for non mandatory parameters Optional can be used:

So I think this is a valid exception to the rule as spring mvc cares about it that the optional itself is not null.

Kind regards,

Hello @reitzmichnicht

I think this makes sense, ticket created: SONARJAVA-4169.

Thanks for the feedback and for providing references.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.