gluonhq / attach

GNU General Public License v3.0
49 stars 26 forks source link

prevent NPE in Util #344

Closed jperedadnr closed 1 year ago

jperedadnr commented 1 year ago

This is not safe:

 private static void syncClipboardFromOS() {
        if (Util.activity == null) {
             return;
        }
        Util.activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                new Handler(Util.activity.getMainLooper()).postDelayed(new Runnable() {

because Util can be called from several services. While the first null check is correct, in #383 StorageService asks for some permissions, and then it nullifies Util.activity before the handler is created, causing a NPE in Util.activity.getMainLooper().

Therefore, a second null check is required.