Как подавить предупреждения FindBugs для полей или локальных переменных
Я хотел бы подавить предупреждения FindBugs для определенных полей или локальных переменных. FindBugs документирует, что целью может быть Тип, Поле, Метод, Параметр, Конструктор, Пакет для его аннотации edu.umd.cs.findbugs.annotations.SuppressWarning [1]. Но для меня не работает аннотирование поля, только когда я аннотирую метод, предупреждение подавляется.
Аннотирование всего метода кажется мне широким. Есть ли способ подавления предупреждений в определенных полях? Есть еще один связанный вопрос [2], но ответа нет.
[1]http://findbugs.sourceforge.net/manual/annotations.html
[2]Подавлять предупреждения FindBugs в Eclipse
Демо-код:
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
}
}