Files
openide/java/java-impl/resources/inspectionDescriptions/UseOfAnotherObjectsPrivateField.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

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>