SonarLint showed "!unknown!::this.!unknownMethod!" as a suggestion for replacing method reference

Please provide

  • Operating system: Windows 10
  • SonarLint plugin version: 6.7.0.45926
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

When using Android Studio with Java code, I experienced an issue where SonarLint correctly spotted a case where a lambda could be converted to a method reference, but it gave the method reference as “!unknown!::this.!unknownMethod!”, and when using the quick action, it replaced the lambda with this (which caused a compilation error).

The issue seems to be related to using an Android R value within the method call which accepts the lambda. I have got a reproducible example as follows:

public class Example {
    public void foo() {

    }

    public void bar(int iconResourceId, Runnable runnable) {

    }

    protected void baz() {
        Runnable r = () -> bar(R.string.help, () -> foo());
        r.run();
    }
}

Here, R.string.help was a simple string defined within my app. The same issue didn’t occur when using strings from android.R (for example “android.R.string.yes” which is defined in the Android framework rather than my app). However it happens with any resource that’s defined within my app.

I am on the latest version of Android Studio (Chipmunk Patch 1).

The specific message displayed by SonarLint is:

Replace this lambda with method reference '!unknown!.this::!unknownMethod!'.

It should have displayed:

Replace this lambda with method reference 'Example.this::foo'.