android-retrolambda-lombok
android-retrolambda-lombok copied to clipboard
Threading annotations hit on lambda, not class or method ref
Here's a minimum representative sample which illustrates the problem:

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.
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.
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.