Write to static field - is FindBugs wrong in this case?
- by htorque
I have a Java class like this:
public class Foo {
public static int counter = 0;
public void bar(int counter) {
Foo.counter = counter;
}
}
FindBugs warns me about writing to the static field counter via the instance method bar. However, if I change the code to:
public class Foo {
public static int counter = 0;
public static void setCounter(int counter) {
Foo.counter = counter;
}
public void bar(int counter) {
setCounter(counter);
}
}
Then FindBugs won't complain. Isn't that wrong? I'm still writing to a static field from an instance method, just via a static method - no?