A RetroSearch Logo

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

Search Query:

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

[java] AvoidPrintStackTrace can't detect the case e.getCause().printStackTrace() · Issue #2437 · pmd/pmd · GitHub

Affects PMD Version:
6.22.0
Rule:
AvoidPrintStackTrace

Description:
Can't detect the case that call printStackTrace() by a method, for example: e.getCause().printStackTrace();. This rule is implemented through xpath search:

<![CDATA[
//PrimaryExpression
 [PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
 [PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]
]]>

AST analyse result:

<PrimaryPrefix FindBoundary='false' Image='' SingleLine='true' SuperModifier='false' ThisModifier='false'>
<Name FindBoundary='false' Image='e.getCause' 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>
<PrimarySuffix ArgumentCount='-1' Arguments='false' ArrayDereference='false' FindBoundary='false' Image='printStackTrace' SingleLine='true' />
<PrimarySuffix ArgumentCount='0' Arguments='true' ArrayDereference='false' FindBoundary='false' Image='' SingleLine='true'>
<Arguments ArgumentCount='0' FindBoundary='false' Image='' SingleLine='true' Size='0' />
</PrimarySuffix>

In the case e.getCause().printStackTrace();, AST chain is: PrimaryPrefix-> PrimarySuffix-> PrimarySuffix(printStackTrace)

Code Sample demonstrating the issue:

try {
    doSomething();
} catch(InvocationTargetException e) {
    e.getCause().printStackTrace();
}

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