Skip to content

[maven] Classloader not being closed after PMD run #2163

Closed as not planned
Closed as not planned

Description

@cwholmes

Affects PMD Version:
Unknown: Definitely 6.18.0+

Rule:

Description:
Classloader is being constructed in the configuration and then never closed.

https://github.com/pmd/pmd/blob/master/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java#L196

This classloader is then never closed and is being left to be close the open jar file references when finalized. This seems to be keeping open file references to jarfiles. (Also duplicating them across threads).

Code Sample demonstrating the issue:

Example of classloader that isn't closed:

maven-pmd-plugin

Running PMD through: [Maven]

Activity

  1. added
    a:bug
    on Feb 4, 2020
  2. adangel commented on Feb 4, 2020

    @adangel
    Member

    Inside PMD - meaning, when running PMD from commandline or via the provided ant task, there is no problem:

    It seems, how the maven-pmd-plugin calls PMD, the classloader is not closed, though.

    I'll keep this issue open, maybe we can improve the API, so that such situation is not even possible. The API caller shouldn't have to deal with that problem.

    There might be a similar problem for the https://github.com/pmd/pmd-eclipse-plugin.

    See also:

  3. changed the title [-][java] Classloader not being closed after PMD run.[/-] [+][java] Classloader not being closed after PMD run[/+] on Feb 4, 2020
  4. added this to the 7.0.0 milestone on Oct 28, 2020
  5. adangel commented on Jan 13, 2023

    @adangel
    Member

    This is still open - we still use a classloader via PMDConfiguration, which needs to be closed.

    This is not a problem, as long as PMD is used as described in https://pmd.github.io/latest/pmd_userdocs_tools_java_api.html.

    But if PMD is used differently, or a PMDConfiguration is created without calling PmdAnalysis, then one might still run into this issue.

  6. changed the title [-][java] Classloader not being closed after PMD run[/-] [+][core] Classloader not being closed after PMD run[/+] on Jan 13, 2023
  7. modified the milestones: 7.0.0, 7.x on Jan 23, 2023
  8. added
    needs:pmd7-revalidation
    and removed
    needs:pmd7-revalidation
    on Apr 2, 2024
  9. changed the title [-][core] Classloader not being closed after PMD run[/-] [+][maven] Classloader not being closed after PMD run[/+] on Apr 3, 2024
  10. jsotuyod commented on Apr 3, 2024

    @jsotuyod
    Member

    @adangel so if I understand correctly, this lies 100% on the Maven plugin, that is tightly bound to PMD using it's internal APIs (part of the reason why the pmd-compat6 module was needed); with nothing to do on this end.

    Do you want to keep it here? or do you have a corresponding issue on the Maven plugin's JIRA?

  11. adangel commented on Apr 11, 2024

    @adangel
    Member

    The closing part has been fixed in m-pmd-p 3.14.0 already.
    As #4949 / #4899 showed, the classloader is definitely closed in maven-pmd-plugin still today. So, there is no problem in this regard anymore.

    The only thing left here is:

    I'll keep this issue open, maybe we can improve the API, so that such situation is not even possible. The API caller shouldn't have to deal with that problem.

    That's an API problem: Whoever calls PMDConfiguration#prependAuxClasspath might create an Classloader, that might not be closed.

    Right now, when calling PMD via PmdAnalysis, the classloader is closed when PmdAnalysis is closed. So, it should not be a problem anymore, if PmdAnalysis is closed.

    However, I find it still surprising, that PMDConfiguration manages a classloader instead of a classpath...

    Two things, I'd suggest:

    1. document in the API for PMDConfiguration#prependAuxClasspath and the related methods (setClassloader, getClassloader) the implications of not properly closing the classloader.
    2. deprecate setClassloader/getClassloader, refactor PMDConfiguration to deal with a list of strings (a "classpath") and create the classloader only later, fully internally and not exposing this classloader in any way.
  12. removed this from the 7.x milestone on Apr 11, 2024
  13. adangel commented on Apr 11, 2024

    @adangel
    Member

    Closing this one now in favor of #4952 and #4953.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugwas:invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions