You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] CloseResource: False positive with resource being closed in method #4623
Description:
PMD warns in line 11, while the resource c gets closed in the function closeConnection. Code Sample demonstrating the issue:
Maybe a false positive:
importjava.sql.Connection;
importnet.sourceforge.pmd.lang.java.rule.errorprone.closeresource.Pool;
publicclassFoo {
voidcloseConnection(Connectionc) {
c.close();
}
voidbar(Poolpool) {
Connectionc = pool.getConnection();
try {
} catch (Exceptione) {
} finally {
// a lambda has the same effectcloseConnection(c);
}
}
}
changed the title [-][java] CloseResource: false positive with method call[/-][+][java] CloseResource: False positive with resource being closed in method[/+]on Jun 23, 2026
Activity
adangel commentedon Jul 6, 2023
You could configure the rule property "closeTargets" like this:
However, since this is all within one class, it would be nice if PMD could detect this on its own (through some basic call flow).
[-][java] CloseResource: false positive with method call[/-][+][java] CloseResource: False positive with resource being closed in method[/+][java] Fix pmd#4623: CloseResource: False positive with resource bein…