mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
31 lines
1.2 KiB
HTML
31 lines
1.2 KiB
HTML
<html>
|
|
<body>
|
|
Reports accesses to <code>private</code> or <code>protected</code> fields of another object.
|
|
Java allows access to such fields for objects of the same class as the current object but
|
|
some coding styles discourage this use. Additionally, such direct access to <code>private</code> 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.
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
public class Base {
|
|
protected int bar;
|
|
|
|
void increment(Base base) {
|
|
bar++;
|
|
base.bar++; // warning: direct access to another object's non-public field
|
|
}
|
|
}
|
|
</code></pre>
|
|
A quick-fix to encapsulate the field is available.
|
|
<!-- tooltip end -->
|
|
<p>Configure the inspection:</p>
|
|
<ul>
|
|
<li>Use the <b>Ignore accesses from the same class</b> option to ignore access from the same class and only report access
|
|
from inner or outer classes.
|
|
<p>To ignore access from inner classes as well, use the nested <b>Ignore accesses from inner classes</b>.</p>
|
|
</li>
|
|
<li>Use the <b>Ignore accesses from 'equals()' method</b> to ignore access from an <code>equals()</code> method.</li>
|
|
</ul>
|
|
</body>
|
|
</html> |