Skip to content

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

Closed
@adangel

Description

@adangel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions