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

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&lt;&gt;());
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&lt;&gt;());
return props.getProperty("hello");
}
</code></pre>
<!-- tooltip end -->
</body>
</html>