Closed
Description
Affects PMD Version:
6.22.0
Rule:
UseNotifyAllInsteadOfNotify
Description:
UseNotifyAllInsteadOfNotify falsely detect a special case with argument: foo.notify(bar)
This rule is implemented through xpath search:
<![CDATA[
//StatementExpression/PrimaryExpression
[PrimarySuffix/Arguments[@Size = '0']]
[
PrimaryPrefix[
./Name[@Image='notify' or ends-with(@Image,'.notify')]
or ../PrimarySuffix/@Image='notify'
or (./AllocationExpression and ../PrimarySuffix[@Image='notify'])
]
]
]]>
AST analyse result of the code sample:
<StatementExpression FindBoundary='false' Image='' SingleLine='true'>
<PrimaryExpression FindBoundary='false' Image='' SingleLine='true'>
<PrimaryPrefix FindBoundary='false' Image='' SingleLine='true' SuperModifier='false' ThisModifier='false'>
<Name FindBoundary='false' Image='getInjector' SingleLine='true' />
</PrimaryPrefix>
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
<Arguments ArgumentCount='0' BeginColumn='28' BeginLine='420' EndColumn='29' EndLine='420' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>
<PrimarySuffix ArgumentCount='-1' Arguments='false' ArrayDereference='false' FindBoundary='false' Image='notify' SingleLine='true' />
<PrimarySuffix ArgumentCount='3' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
<Arguments ArgumentCount='3' FindBoundary='false' Image='' SingleLine='true' Size='3'>
<ArgumentList BeginColumn='38' BeginLine='420' EndColumn='73' EndLine='420' FindBoundary='false' Image='' SingleLine='true' Size='3'>
......
In the case getInjector().notify(getCanonicalName(), e.getMessage(), e)
, the fifth line of the AST analysis result is <PrimarySuffix ArgumentCount='0'
, which causes detection even when notify()
with argument.
Code Sample demonstrating the issue:
getInjector().notify(getCanonicalName(), e.getMessage(), e);
Expected outcome:
false-positive
Running PMD through:
CLI