mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<html>
|
|
<body>
|
|
Reports calls to the following methods on <code>java.util.Properties</code> objects:
|
|
<ul>
|
|
<li><code>put()</code></li>
|
|
<li><code>putIfAbsent()</code></li>
|
|
<li><code>putAll()</code></li>
|
|
<li><code>get()</code></li>
|
|
</ul>
|
|
<p>
|
|
For historical reasons, <code>java.util.Properties</code> inherits from <code>java.util.Hashtable</code>,
|
|
but using these methods is discouraged to prevent pollution of properties with values of types other than <code>String</code>.
|
|
</p>
|
|
<p>
|
|
Calls to <code>java.util.Properties.putAll()</code> won't get reported when
|
|
both the key and the value parameters in the map are of the <code>String</code> type.
|
|
Such a call is safe and no better alternative exists.
|
|
</p>
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
Object f(Properties props) {
|
|
props.put("hello", "world");
|
|
props.putIfAbsent("hello", "world");
|
|
props.putAll(new HashMap<>());
|
|
return props.get("Hello");
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
Object f(Properties props) {
|
|
props.setProperty("hello", "world");
|
|
props.putIfAbsent("hello", "world");
|
|
props.putAll(new HashMap<>());
|
|
return props.getProperty("hello");
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html> |