So unterdrücken Sie FindBugs-Warnungen für Felder oder lokale Variablen

Ich würde gerne unterdrücken FindBugs-Warnungen für bestimmte Felder oder lokale Variablen. FindBugs Dokumente, die die Target Type, Field, Method, Parameter, Konstruktor-Paket für Ihre edu.umd.cs.findbugs.Anmerkungen.SuppressWarning Anmerkung [1].
Aber es funktioniert nicht für mich zu kommentieren das Feld, nur wenn ich kommentieren die Methode der Warnung wird unterdrückt.

Anmerkungen eine ganze Methode scheint zu breit für mich. Gibt es eine Möglichkeit zu unterdrücken, Warnhinweise auf bestimmten Feldern? Es ist eine weitere Frage im Zusammenhang mit [2], aber keine Antwort.

[1] http://findbugs.sourceforge.net/manual/annotations.html

[2] Unterdrücken FindBugs-Warnungen in Eclipse

Demo-code:

public class SyncOnBoxed
{
    static int counter = 0;
    //The following SuppressWarnings does NOT prevent the FindBugs warning
    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE")
    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="DL_SYNCHRONIZATION_ON_BOXED_PRIMITIVE")
    protected static boolean increment(Long expiringLock)
    {
        synchronized (expiringLock) { //<<< FindBugs warning is here: Synchronization on Long in SyncOnBoxed.increment()
            counter++;
        }
        return expiringLock > System.currentTimeMillis(); //return false when lock is expired
    }
}

InformationsquelleAutor der Frage Christian Esken | 2013-01-24

Schreibe einen Kommentar