Skip to content

[java] DontCallThreadRun can't detect the case that call run() in foo.bar.run() #2538

@wuchiuwong

Description

@wuchiuwong

Affects PMD Version:
6.22.0
Rule:
DontCallThreadRun

Description:
DontCallThreadRun can't detect the case that call run() in foo.bar.run(). This rule is implemented through xpath search: 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 FindBoundary='false' Image='' SingleLine='true' SuperModifier='false' ThisModifier='false'>
	<Name FindBoundary='false' Image='client.blink.run' SingleLine='true' />
</PrimaryPrefix>
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
	<Arguments ArgumentCount='0' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>

Possible error when detecting whether the type of client.blink is java.lang.Thread

Code Sample demonstrating the issue:

client.blink.run();

Expected outcome:
false-negative

Running PMD through:
CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions