forked from phoedos/pmd
Adding a new rule 'UseConcurrentHashMap' to promote use of ConcurrentHashMap implementation in Java 5
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6997 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
parent
a73b7f1fb1
commit
1d7d5e6474
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<test-data>
|
||||||
|
<test-code>
|
||||||
|
<description><![CDATA[
|
||||||
|
Basic use case
|
||||||
|
]]></description>
|
||||||
|
<expected-problems>2</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
private Map _map = new TreeMap();
|
||||||
|
|
||||||
|
public void m() {
|
||||||
|
Map m = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map contructMap() {
|
||||||
|
return new HashMap(); //not detected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
</test-data>
|
@ -712,6 +712,36 @@ public class PrimitiveType {
|
|||||||
</example>
|
</example>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UseConcurrentHashMap"
|
||||||
|
since="4.2.6"
|
||||||
|
message="If you run in Java5 and have concurrent access, you should use ConcurrentHashMap implementation"
|
||||||
|
class="net.sourceforge.pmd.rules.XPathRule"
|
||||||
|
externalInfoUrl="http://pmd.sourceforge.net/rules/controversial.html#UseConcurrentHashMap">
|
||||||
|
<description>
|
||||||
|
Since Java5 brought a new implementation of the Map interface, specially designed for concurrent application.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//Type[../VariableDeclarator/VariableInitializer]/ReferenceType/ClassOrInterfaceType[@Image = 'Map']
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class ConcurrentApp {
|
||||||
|
public void getMyInstance() {
|
||||||
|
Map map = new HashMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user