-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] Produce a more visible error when not calling SDK methods from the UiThread #9896
Comments
cc: @tobrun |
To add something to this one - there is no way to add code to an existing Java class via an annotation processor. There was a project called Lombok some time ago, but it looks like it's dead and here is the trick they've used. Therefore, I think that only
is applicable here. Another, more complicated approach, would be to wrap all public methods of a class that we want to "thread-check" with an interface and push through Proxy. For example, in
Above change is probably cleaner but it's a |
Great analysis @LukasPaczos, one thing that came to mind for the manual approach is that we can guard a lot of the API through the code generation of the template files. This will cover a large part of the API though we still need to manually update components as MapboxMap, MapView, Projection etc. |
Good point @tobrun, but basically everything that's generated is finally pushed through the pipeline of It seems like all comes down to updating the methods ourselves. |
That is true for most cases but since Layer/Source are peer components, they can execute native code without involving the pipeline. Eg. |
Oh yes, thanks for emphasizing that @tobrun, I missed it. In this case, adding checks to the code templates will cover a decent chunk of the API. |
@UiThread
annotations and calling SDK methods from a background thread.Because thread annotations are simply Lint checks and do not affect one’s build or compilation @ivovandongen suggested that we can do two things here, depending on how many methods it concerns:
A compilation-time error would be ideal, but if that's not possible a runtime error would be ok.
cc/ @jfirebaugh @ivovandongen @zugaldia
The text was updated successfully, but these errors were encountered: