kotlin:S1481 false positive

Hi all, we are seeing a lot of false positives when we have code like this:

val foo = something ?: error("Some error")
val bar = somethingElse ?: error("Some other error")

We are using both foo and bar on the next line, but Sonar gets confused and reports a “Unused local variables should be removed”.

I understand that handling that error([...]) must not be trivial, and I don’t want to disable the check because is very useful in a lot of other places in the codebase, but these examples are definitely false positives.

Thanks for your help,
Ivan

Hey @ivanmorgillo

Please read this thread regarding reporting false-positives:

(We’re missing what product you’re using and what version if applicable)

Hi Colin and thank you for your patience.

I’m using the IntelliJ Ultimate Plugin Sonarlint 6.5.1.43866 (SonarLint - IntelliJ IDEs Plugin | Marketplace).

Hey Ivan,

I looked into the issue you describe and could unfortunately not reproduce it. We did have a couple of false positives with this rule in the past, when projects were not ideally configured (see this ticket), however this should be fixed in current versions of all products.

Can you please confirm whether or not you are running SonarLint in connected mode? If you are running it in connected mode, is it connected to a SonarQube server or SonarCloud? If it is SonarQube, which version?