android-retrolambda-lombok icon indicating copy to clipboard operation
android-retrolambda-lombok copied to clipboard

Threading annotations hit on lambda, not class or method ref

Open JakeWharton opened this issue 10 years ago • 2 comments

Here's a minimum representative sample which illustrates the problem: screen shot 2015-08-31 at 5 49 58 pm

Now this code is 100% contrived. One could imagine doInBackground using an Executor or hell, AsyncTask. But for the purposes of the bug it actually needs no implementation.

For copy/paste:

  @WorkerThread static void doSomething() {}
  static void doInBackground(Runnable r) {}

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    doInBackground(new Runnable() {
      @Override public void run() {
        doSomething();
      }
    });
    doInBackground(() -> doSomething());
    doInBackground(MainActivity::doSomething);
  }

Now I don't know about the implementation of this library, but it seems like it is exposing the code inside of the lambda to lint as if it were a part of the surrounding method rather than nested in a context similar to an anonymous class. Ideally the behavior would be exactly that as an anonymous class but I don't know if you have all the information needed for that or not.

JakeWharton avatar Aug 31 '15 21:08 JakeWharton

The implementation actually wraps the body in a LambdaExpression node which currently only holds the body of the lambda. Lint implementations not expecting this node (all of them) just end up skipping over it so it's not surprizing that they think the lambda body is in the surrounding context. I have not investigated if there is enough information to fake a full anonymous inner class, as I just implemented the bare minimum to get lint working.

evant avatar Aug 31 '15 22:08 evant

Since this fork is no longer needed with plugin 2.2.0 or newer, I've moved the bug to http://b.android.com/223101 since it persists in the official implementation.

JakeWharton avatar Sep 20 '16 21:09 JakeWharton