A RetroSearch Logo

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

Search Query:

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

false positive when using builder pattern · Issue #422 · pmd/pmd · GitHub

Rule Set:

rulesets/java/design.xml/PreserveStackTrace

Description:

The PreserveStackTrace tries to detect when stack trace is preserved when the exception is wrapped as an inner exception, but fails when using a builder-like pattern, see the third throw in the code snippet below.

Code Sample demonstrating the issue:

public final class Main {

    public void execute() {
        final String dirname = "c:/temp";

        try {
            FileUtils.deleteDirectoryContent(Paths.get(dirname));
        } catch (final IOException e) {
            throw new ApplicationException("Error"); // throw 1: true positive
        }

        try {
            FileUtils.deleteDirectoryContent(Paths.get(dirname));
        } catch (final IOException e) {
            throw new ApplicationException("Error", e); // throw 2: true negative
        }

        try {
            FileUtils.deleteDirectoryContent(Paths.get(dirname));
        } catch (final IOException e) {
            throw uncheckedException(ErrorCodeCommon.DIRECTORY_NOT_FOUND) // throw 3: false positive
                    .withField("dirname", dirname)
                    .causedBy(e) 
                    .build(); 
        }
    }
}

Running PMD through: CLI

pmd.bat -d ClearAdditionalDebugData.java -f xml -R rulesets/java/design.xml/PreserveStackTrace

Outputs:

<?xml version="1.0" encoding="UTF-8"?>
<pmd version="5.6.1" timestamp="2017-06-02T16:12:47.550">
<file name="E:\tickets\18522\bin\ClearAdditionalDebugData.java">
<violation beginline="9" endline="9" begincolumn="13" endcolumn="52" rule="PreserveStackTrace" ruleset="Design" class="Main" method="execute" externalInfoUrl="h
ttps://pmd.github.io/pmd-5.6.1/pmd-java/rules/java/design.html#PreserveStackTrace" priority="3">
New exception is thrown in catch block, original stack trace may be lost
</violation>
<violation beginline="21" endline="22" begincolumn="13" endcolumn="29" rule="PreserveStackTrace" ruleset="Design" class="Main" method="execute" externalInfoUrl=
"https://pmd.github.io/pmd-5.6.1/pmd-java/rules/java/design.html#PreserveStackTrace" priority="3">
New exception is thrown in catch block, original stack trace may be lost
</violation>
</file>
</pmd>

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