mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
25 lines
1.0 KiB
HTML
25 lines
1.0 KiB
HTML
<html>
|
|
<body>
|
|
Reports implementations of <code>InvocationHandler</code> that do not proxy standard
|
|
<code>Object</code> methods like <code>hashCode()</code>, <code>equals()</code>, and <code>toString()</code>.
|
|
<p>Failing to handle these methods might cause unexpected problems upon calling them on a proxy instance.</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
InvocationHandler myHandler = (proxy, method, params) -> {
|
|
System.out.println("Hello World!");
|
|
<b>return</b> null;
|
|
};
|
|
Runnable myProxy = (Runnable) Proxy.newProxyInstance(
|
|
Thread.currentThread().getContextClassLoader(),
|
|
<b>new</b> Class[] {Runnable.class}, myHandler
|
|
);
|
|
</code></pre>
|
|
<p>
|
|
This code snippet is designed to only proxy the <code>Runnable.run()</code> method.
|
|
However, calls to any <code>Object</code> methods, like <code>hashCode()</code>, are proxied as well.
|
|
This can lead to problems like a <code>NullPointerException</code>, for example, when adding <code>myProxy</code> to a <code>HashSet</code>.
|
|
</p>
|
|
<!-- tooltip end -->
|
|
<p><small>New in 2020.2</small>
|
|
</body>
|
|
</html> |