"Unused local variables should be removed" is broken

Please provide

  • Operating system: Windows 10
  • SonarLint plugin version:
  • Programming language you’re coding in: kotlin
  • Is connected mode used:
    • Connected to SonarCloud or SonarQube (and which version): Sonarlint with Intellij

And a thorough description of the problem / question:
github : memes-api/SignService.kt at master · GHGHGHKO/memes-api · GitHub

    fun signIn(signInRequestDto: SignInRequestDto): SignInResponseDto {
        val user: UserMaster = userMasterRepository.findByEmail(signInRequestDto.email)
            ?: throw UserNotFoundExceptionCustom()

        if (!passwordEncoder.matches(signInRequestDto.password, user.password)) {
            throw EmailSignInFailedExceptionCustom()

        val jwtInfo = jwtTokenProvider.createToken(user.id.toString(), user.roles)

        return SignInResponseDto(
            jwtInfo.token, jwtInfo.expirationDate

user variables is Unused local variables should be removed


Welcome to the community!

It looks like SonarLint 6.8 has some age on it at this point. Could you upgrade to the current version,, and see if this is replicable?


1 Like

Hi, G Ann Campbell!

Thank you for your reply

Updated from version 6.8 to version
See this issue is replicated
Is it because didn’t return a variable?


Thanks for trying with the updated version. Unfortunately, I can’t answer your question, so I’ve flagged this for more expert eyes.



Thanks for the quick reply!
I’m looking forward to awesome results!

1 Like


Thanks for your report. I was able to reproduce this issue when analyzing the single file. However, when I analyze the whole project, this issue disappears. This means that the problem is that SonarLint wasn’t able to locate the .class files of your project correctly. And without semantics, the analyzer is not able to resolve variables, types, and bindings correctly, which leads to the incorrect result.

For now, I can suggest you build your project with Gradle (either from the IDE or command line), make sure that the build folder is generated, and then run the analysis. The issue should disappear.

Meanwhile, I created a ticket to not report FPs in case of incomplete semantics:


Kind regards,

1 Like

Hello Margarita Nedzelska,
Thanks for the quick comment and explaining the problem!

Thanks for issuing the tickets.
I’ll be checking the ticket!


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