Rule java:S6814 "Optional REST parameters should have an object type" false positive

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?

Java

  • Which rule?

java:S6814 Optional REST parameters should have an object type

  • Why do you believe it’s a false-positive/false-negative?

Spring supports optional primitive boolean parameters. For example following seems to work:

@RequestParam(value = "test", required = false) final boolean test

Using a debugger I get value false when I do not pass any value for the parameter.

  • Are you using
    • SonarCloud?
    • SonarQube - which version?
      10.4.1
    • SonarLint - which IDE/version?
      • in connected mode with SonarQube or SonarCloud?
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

Add RequestParam of type boolean and optional=true into a Spring controller method and do not pass any value in the request.