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] CloseResource false-positive with URLClassLoader in cast expression #2056

Closed
adangel opened this issue Oct 5, 2019 · 0 comments · Fixed by #4906
Closed

[java] CloseResource false-positive with URLClassLoader in cast expression #2056

adangel opened this issue Oct 5, 2019 · 0 comments · Fixed by #4906
Labels
a:false-positive PMD flags a piece of code that is not problematic has:pr The issue is already tackled in a PR
Milestone

Comments

@adangel
Copy link
Member

adangel commented Oct 5, 2019

That one could be considered a FP, since we don't create the URLClassLoader here. We just cast the method argument, which is a ClassLoader, to a local variable, which is a URLClassLoader and therefore AutoCloseable...

_Originally posted by @adangel in #1955 _

Code example:

public void checkValidity(final RuleSets ruleSets, final ClassLoader auxclassPathClassLoader) {
boolean cacheIsValid = cacheExists();
if (cacheIsValid && ruleSets.getChecksum() != rulesetChecksum) {
LOG.info("Analysis cache invalidated, rulesets changed.");
cacheIsValid = false;
}
final long currentAuxClassPathChecksum;
if (auxclassPathClassLoader instanceof URLClassLoader) {
final URLClassLoader urlClassLoader = (URLClassLoader) auxclassPathClassLoader;

The variable "urlClassLoader" is not closed in this method and this is detected by the rule.
However, since the URLClassLoader is not created within this method, it should be ignored.

@adangel adangel added the a:false-positive PMD flags a piece of code that is not problematic label Oct 5, 2019
@adangel adangel changed the title CloseResource false-positive with URLClassLoader in cast expression [java] CloseResource false-positive with URLClassLoader in cast expression Oct 5, 2019
@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@jsotuyod jsotuyod removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 31, 2024
jsotuyod added a commit to Monits/pmd that referenced this issue Mar 31, 2024
jsotuyod added a commit to Monits/pmd that referenced this issue Mar 31, 2024
@jsotuyod jsotuyod added the has:pr The issue is already tackled in a PR label Mar 31, 2024
@adangel adangel added this to the 7.1.0 milestone Apr 4, 2024
@adangel adangel closed this as completed in 44b7e21 Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic has:pr The issue is already tackled in a PR
Projects
None yet
2 participants