title: How to tell Android Studio that a variable may become null?
body: <p>I have the following code, where the second "Callback" parameter MUST be supplied by the caller (the reason why I have annotated it with @Nonnull).</p>
  
  <pre><code>public static void load(@Nonnull final String channelId, @Nonnull final Callback callback) {
      Observable.create(new Observable.OnSubscribe&lt;Channel&gt;() {
          @Override public void call(Subscriber&lt;? super Channel&gt; subscriber) {
              try {
                  Channel channel = new Channel().setApiChannel(MobileService.api().channels().get(channelId).execute(), UpdateFields.ALL);
                  subscriber.onNext(channel);
              } catch (Exception e) {
                  subscriber.onError(e);
              }
              subscriber.onCompleted();
          }
      }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()). subscribe(new Subscriber&lt;Channel&gt;() {
          @Override public void onCompleted() {
          }
          @Override public void onError(Throwable t) {
              log.warning("could not load channelId = " + channelId + ", throwable = " + t.getMessage());
              if (callback != null) { callback.onError(channelId, t); }
          }
          @Override public void onNext(Channel channel) {
              if (callback != null) { callback.onSuccess(channel); }
          }
      });
  }
  </code></pre>
  
  <p>The Callback interface looks like this:</p>
  
  <pre><code>public interface Callback {
      void onSuccess(Channel channel);
      void onError(String channelId, Throwable throwable);
  }
  </code></pre>
  
  <p>To call back the caller, I make a null check like this</p>
  
  <pre><code>if (callback != null) { callback.onSuccess(channel); }
  </code></pre>
  
  <p>because the caller could become null any time while my observable does its background job. For example, the caller might be a view which could be paused/destroyed/garbage collected [Android does funny things sometimes], in which case my code would fail without the null check.</p>
  
  <p>But Android Studio does not recognize that possibility and displays a Lint warning, which it doesn't allow me to suppress either.</p>
  
  <p><img src="https://i.stack.imgur.com/jnenf.png" alt="Callback"></p>
  
  <p>It seems Android Studio does not realize the variable could become null by other causes except my own function. Well, I even admit it should not as it is final, and I was very surprised when that line initially failed (I didn't have the null check at that point because I believed it could never become null).</p>
  
  <p>Question: How can I tell Android Studio to suppress the warning, despite the parameter being annotated as @Nonnull final?</p>
  
  <p>And then: If somebody could explain how the final variable can become null at any time when the underlying reference becomes null. My concept of final is the variable is "cloned" and kept with the context, which is obviously not happening here. Is final "forward only" - meaning my own code cannot change that variable anymore, but the caller still can?</p>