title: How do I use @CheckForNull etc with Findbugs?
body: <p>When I run this through Findbugs, I get a warning:</p>
  
  <pre><code>static @NonNull Object foo(@CheckForNull Object arg) {
      if (arg == null) { // warning on this line
          throw new NullPointerException();
      }
      return "something";
  
  }
  </code></pre>
  
  <p>The details of the warning is the following:</p>
  
  <blockquote>
    <p>Bug: <code>arg</code> must be nonnull but is marked as nullable<br>
    Pattern id: <code>NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE</code>, type: <code>NP</code>, category: <code>STYLE</code></p>
    
    <p>This parameter is always used in a way that requires it to be nonnull, but the parameter is explicitly annotated as being <code>Nullable</code>. Either the use of the parameter or the annotation is wrong. </p>
  </blockquote>
  
  <p>Can someone explain what Findbugs is complaining about here?</p>
  
  <p>Note that I'm using the <code>edu.umd.cs.findbugs.annotations.*</code> members, not the <code>javax.annotations.*</code>. (Is there a difference?)</p>
  
  <p>Set up is FindBugs plug-in 1.3.9.2009- for Eclipse 3.6.1.</p>
  
  <hr>
  
  <p>Matthew Flaschen suggested that I use <code>@NonNull</code> instead, but now I ran into this problem:</p>
  
  <pre><code>static void blah(@NonNull Object arg) {
      if (arg == null) {
          throw new NullPointerException();
      }
      System.out.println(arg);
  }
  
  static @CheckForNull Object bleh() {
      return null;
  }
  
  //...
  blah(bleh()); // warning here!
  </code></pre>
  
  <p>The details of the warning is:</p>
  
  <blockquote>
    <p>Bug: Possible null pointer dereference due to return value of called method<br>
    Pattern id: <code>NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE</code>, type: <code>NP</code>, category: <code>STYLE</code></p>
    
    <p>The return value from a method is dereferenced without a <code>null</code> check, and the return value of that method is one that should generally be checked for <code>null</code>. This may lead to a <code>NullPointerException</code> when the code is executed.</p>
  </blockquote>
  
  <p>I basically want <code>blah</code> to satisfy the <code>@CheckForNull</code> requirement, but I can't do it if I make its arg be <code>@NonNull</code>. How do I get this to work?</p>