#1342 UseConcurrentHashMap false positive (with documentation example)

This commit is contained in:
Andreas Dangel
2015-04-30 20:07:54 +02:00
parent 770fc5763e
commit 857ae074e1
3 changed files with 20 additions and 1 deletions

View File

@ -851,7 +851,8 @@ perform efficient map reads without blocking other threads.
<property name="xpath">
<value>
<![CDATA[
//Type[../VariableDeclarator/VariableInitializer//AllocationExpression]/ReferenceType/ClassOrInterfaceType[@Image = 'Map']
//Type[../VariableDeclarator/VariableInitializer//AllocationExpression/ClassOrInterfaceType[@Image != 'ConcurrentHashMap']]
/ReferenceType/ClassOrInterfaceType[@Image = 'Map']
]]>
</value>
</property>

View File

@ -27,6 +27,22 @@ public class Foo {
public void m() {
final Map myMap = myObject.methodThatReturnMap();
}
}
]]></code>
</test-code>
<test-code>
<description>#1342 UseConcurrentHashMap false positive (with documentation example)</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>3</expected-linenumbers>
<code><![CDATA[
public class ConcurrentApp {
public void getMyInstance() {
Map map1 = new HashMap(); // fine for single-threaded access --- violation on this line
Map map2 = new ConcurrentHashMap(); // preferred for use with multiple threads
// the following case will be ignored by this rule
Map map3 = someModule.methodThatReturnMap(); // might be OK, if the returned map is already thread-safe
}
}
]]></code>
</test-code>

View File

@ -12,4 +12,6 @@
**Bugfixes:**
* [#1342](https://sourceforge.net/p/pmd/bugs/1342/): UseConcurrentHashMap false positive (with documentation example)
**API Changes:**