SonarLint on Android Studio cannot detect some rules

If your question is about SonarLint in the IntelliJ Platform, VS Code, Visual Studio, or Eclipse, please post it in that sub-category.

Otherwise, please provide:

  • Operating system: MacOS 12.1
  • IDE name and flavor/env: Android Studio Chipmunk

And a thorough description of the problem / question:
Hi, when we analyze the code with SonarLint, we only find 2/3 issues compared to SonarQube analysis. Understand about some “meta rules” that cannot be included in the SonarLint analysis. However, I found out that even “deprecated code” rule cannot be detected in the SonarLint. Is it a bug?

Thanks.

Hey there.

What version of SonarLint are you using, and what version of SonarQube? Are you using Connected Mode?

Hi,

For SonarLint, we are using the latest version, 6.7.
For SonarQube, we are using sonar scanner for Gradle, 3.3.

We are not using the Connected Mode. However, we check one of the rule (Kotlin), “Code annotated as deprecated should not be used”, is not reported by the SonarLint, though we have already included it via the plugin setting.

Thanks,
Daniel

Hello Daniel,

I was not able to reproduce on my side with the latest version (6.8.0). I correctly get an issue with kotlin:S1874 when using some deprecated code.

Could you try this latest version ? If it does not help could you share with us some logs of the analysis ? Could you also send a small reproducer project ? That would greatly help us.

Hi Damien,

I just realize that SonarLint cannot detect the deprecated code when the deprecated code comes from the Java class, while the main class uses Kotlin. Is it expected?
For old Android project, I think it is quite common to have both Java and Kotlin code in the same project.

Here I also attach the sample project.
SonarLint.zip (115.7 KB)

Thank you.

Hey @daniel11,
Sorry for the late reply. AFAIK, deprecated code from Java code used inside of Kotlin code should be flagged by Sonarlint.
But for this to work, Sonarlint and the Kotlin analyzer must be able to read the bytecode of the deprecated class, which in an Android project may be located in a different place than build/classes/{java,kotlin}/.

Can you give us an idea of the layout of your code? Are the java and kotlin code within the same module?

Hi @Dorian_Burihabwa,

We don’t have build/classes/java,kotlin/ in the android project. Instead, we have build/generated, build/intermediates, etc which store the bytecode in the same place.

Can you give us an idea of the layout of your code? Are the java and kotlin code within the same module?

Yes, it is located in the same module. I have attached the sample code on my previous reply.

Thanks,
Daniel

Hey @daniel11,
Thank you for the information. I will need a bit of time investigate the issue. I will get back to you as soon as I know more.