private
or protected
field of another object.
Java allows using such fields for objects of the same class as the current object but
some coding styles discourage this use. Additionally, such direct access to private
fields
may fail in component-oriented architectures, such as Spring or Hibernate, that expect all access
to other objects to be through method calls so the framework can mediate access
using proxies.
Example:
public class Base {
protected int bar;
class Inside {
int f(Base base) {
return base.bar; // warning: direct access to non-public field
}
}
}
class SomewhereElse {
void m(Base base) {
base.bar = 1; // warning: direct access to non-public field
}
}
Configure the inspection:
To ignore access from inner classes as well, use the nested Ignore accesses from inner classes.
equals()
method.