[java] CloseResource: false positive on Statement
A source code analyzer
Brought to you by:
adangel,
juansotuyo
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/
This will be fixed with PMD 5.3.8, 5.4.2 and 5.5.0 and later.
Commit: https://github.com/pmd/pmd/commit/04f16d762722639fd2e28942ce7529bf1396057f
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.
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