Affects PMD Version:
6.22.0
Rule:
DontCallThreadRun
Description:
DontCallThreadRun can't detect the case that call run()
in this.run()
. This rule is implemented through xpath search:
//StatementExpression/PrimaryExpression
[
PrimaryPrefix
[
./Name[ends-with(@Image, '.run') or @Image = 'run']
and substring-before(Name/@Image, '.') =//VariableDeclarator/VariableDeclaratorId/@Image
[../../../Type/ReferenceType/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]]
or (./AllocationExpression/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]
and ../PrimarySuffix[@Image = 'run'])
]
]
AST analyse result of the code sample:
<PrimaryPrefix BeginColumn='17' BeginLine='11' EndColumn='20' EndLine='11' FindBoundary='false' Image='' SingleLine='true' SuperModifier='false' ThisModifier='true' />
<PrimarySuffix ArgumentCount='-1' Arguments='false' ArrayDereference='false' BeginColumn='21' BeginLine='11' EndColumn='24' EndLine='11' FindBoundary='false' Image='run' SingleLine='true' />
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' BeginColumn='25' BeginLine='11' EndColumn='26' EndLine='11' FindBoundary='false' Image='' SingleLine='true'>
<Arguments ArgumentCount='0' BeginColumn='25' BeginLine='11' EndColumn='26' EndLine='11' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>
In the case this.run()
, AST result is: PrimaryPrefix is '', and run
is in PrimarySuffix
Code Sample demonstrating the issue:
public class MatrixThread extends Thread {
public MatrixThread(int[][] m1, int[][] m2) {
this.m1 = m1;
this.m2 = m2;
this.run();
}
Expected outcome:
false-negative
Running PMD through:
CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4