Menu

#1479 [java] CloseResource: false positive on Statement

PMD-5.3.8
closed
java (55)
PMD
3-Major
Bug
5.4.1
CloseResource
2016-06-25
2016-05-06
Geniy00
No

This code triggers violation https://pmd.github.io/pmd-5.4.1/pmd-java/rules/java/design.html#CloseResource
pmd thinks that I used java.sql.Statement

public class Test {

    public static void main(String[] args) {
        Statement statement = new Statement();
    }

    static class Statement {
    }
}

similar bug https://sourceforge.net/p/pmd/bugs/992/

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-05-29
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.8
     
  • Geniy00

    Geniy00 - 2016-05-29

    Hi Andreas,
    Could you please approve that your fix will handle cases when Statement class is in another package?

    https://pmd.github.io/pmd-5.4.1/pmd-java/rules/java/design.html#CloseResource rule is oriented on java.sql.Statement class that must be closed after using. But I have another project class named Statement that triggers false positive.

     
    • Andreas Dangel

      Andreas Dangel - 2016-05-29

      It should work, as long as you use the "auxclasspath" option, see also http://pmd.github.io/pmd-5.4.2/usage/running.html / http://pmd.github.io/pmd-5.4.2/usage/ant-task.html

      Make sure, you do not only add the compileClasspath to this, but also your project's build directory - otherwise PMD won't figure out the correct Statement. The auxclasspath is a requirement for typeresolution in PMD.

      It works good, if you use maven-pmd-plugin - it does this automatically. Gradle has support for the auxclasspath, too (but not fully working yet (see https://github.com/gradle/gradle/pull/649 for a workaround).

      Btw. - I just released PMD 5.4.2

       

      Last edit: Andreas Dangel 2016-05-29
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • labels: --> java
    • summary: CloseResource false positive on Statement --> [java] CloseResource: false positive on Statement
     

Log in to post a comment.