Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] UseTryWithResources - false negative for explicit close #2882

Open
adangel opened this issue Oct 29, 2020 · 0 comments
Open

[java] UseTryWithResources - false negative for explicit close #2882

adangel opened this issue Oct 29, 2020 · 0 comments

Comments

@adangel
Copy link
Member

@adangel adangel commented Oct 29, 2020

Affects PMD Version: 6.30.0-SNAPSHOT

Rule:UseTryWithResources

Description:

From #2871 (comment)

Code Sample demonstrating the issue:

https://chunk.io/pmd/fc7db65b2c6a46eca4c9a0c3012482e2/diff/checkstyle/index.html#A360

import java.io.*;

public class UseTryWithResources {
    void method() throws Exception {
        final String fileName = "Test";
        final BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(fileName), StandardCharsets.UTF_8));
        try { // warning expected: Consider using a try-with-resources statement instead of explicitly closing the resource 
        } finally {
            br.close();
        }
    }
}

Expected outcome:

  • Is PMD missing to report a violation, where there should be one? -> false-negative

Running PMD through: regression-tester

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.