A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2577 below:

[java] UseNotifyAllInsteadOfNotify falsely detect a special case with argument: foo.notify(bar) · Issue #2577 · pmd/pmd · GitHub

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


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