Affects PMD Version:
maven-pmd-plugin 3.13.0 (pmd 6.21.0)
Rule: UseTryWithResources
Description:
PMD Failure: UseTryWithResources when resource is not AutoCloseable and closed via external class which implement AutoCloseable
Code Sample demonstrating the issue:
public class PMDUseTryWithResources {
static class ResourceCloser implements AutoCloseable {
public static void close(NotAutoCloseable notAutoCloseable) {
notAutoCloseable.close();
}
@Override
public void close() throws Exception {
// nothing
}
}
interface NotAutoCloseable {
void close();
}
public void useTryWithResources() {
NotAutoCloseable notAutoCloseable = null;
try {
notAutoCloseable = new NotAutoCloseable() {
@Override
public void close() {
}
};
} finally {
if (notAutoCloseable != null) {
ResourceCloser.close(notAutoCloseable);
}
}
}
}
Steps to reproduce:
- mvn install
Running PMD through: Maven
Affects PMD Version:
maven-pmd-plugin 3.13.0 (pmd 6.21.0)
Rule: UseTryWithResources
Description:
PMD Failure: UseTryWithResources when resource is not AutoCloseable and closed via external class which implement AutoCloseable
Code Sample demonstrating the issue:
Steps to reproduce:
Running PMD through: Maven