#347 new rule: instance variable abuse

open
nobody
None
5
2013-02-16
2011-09-12
Hamlet D'Arcy
No

This is what I call instance variable abuse:

def method() {
foo = 'xyz'
try { ... }
finally {
foo = null
}
}

It is clear that foo (or this.foo) is an instance variable. Yet it is managed only in this single method. What is probably happening is that the method is invoking other code paths into itself and expecting foo to be set. This is really difficult to maintain code.

You should also catch this:

def method() {
foo = 'xyz'

...
foo = null
}

Discussion