title: How to suppress FindBugs warnings for fields or local variables?
body: <p>I would like to suppress FindBugs warnings for specific fields or local variables. FindBugs documents that the <code>Target</code> can be <code>Type</code>, <code>Field</code>, <code>Method</code>, <code>Parameter</code>, <code>Constructor</code>, <code>Package</code> for its <code>edu.umd.cs.findbugs.annotations.SuppressWarning</code> annotation [1].
  But it does not work for me to annotate the field, only when I annotate the method the warning gets suppressed.</p>
  <p>Annotating a whole method seems to broad to me. Is there any way to suppress warnings on specific fields? There is another related question [2], but no answer.</p>
  <p>[1] <a href="http://findbugs.sourceforge.net/manual/annotations.html" rel="nofollow noreferrer">http://findbugs.sourceforge.net/manual/annotations.html</a></p>
  <p>[2] <a href="https://stackoverflow.com/questions/3976328/suppress-findbugs-warnings-in-eclipse">Suppress FindBugs warnings in Eclipse</a></p>
  <p>Demo code:</p>
  <pre><code>public class SyncOnBoxed
  {
      static int counter = 0;
      // The following SuppressWarnings does NOT prevent the FindBugs warning
      @edu.umd.cs.findbugs.annotations.SuppressWarnings(value=&quot;DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE&quot;)
      final static Long expiringLock = new Long(System.currentTimeMillis() + 10);
      
      public static void main(String[] args) {
          while (increment(expiringLock)) {
              System.out.println(counter);
          }
      }
      
      // The following SuppressWarnings prevents the FindBugs warning
      @edu.umd.cs.findbugs.annotations.SuppressWarnings(value=&quot;DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE&quot;)
      protected static boolean increment(Long expiringLock)
      {
          synchronized (expiringLock) { // &lt;&lt;&lt; FindBugs warning is here: Synchronization on Long in SyncOnBoxed.increment()
              counter++;
          }
          return expiringLock &gt; System.currentTimeMillis(); // return false when lock is expired
      }
  }
  </code></pre>