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] Problem with JDK versions, CloseResource and UnnecessarySuppression #6224
ForkJoinPool implements AutoCloseable since JDK 19. This means if you run PMD with a JRE >= 19, CloseResource will trigger and ask the FJP to be used in a try-with-resources. The minimum version we require to build is Java 17, where this violation does not trigger (and we use JDK 17 in CI). I cannot add a suppression comment, as our CI would fail with UnnecessarySuppression, because the violation does not trigger with JDK 17.
This means basically that merging the PR would make PMD build only with JDK 17, but not any later version.
I'm not sure how to get out of this situation. Maybe UnnecessarySuppression should ignore some suppression comments? For now, UnnecessarySuppression cannot be suppressed the normal way, but having a special string in the comment that makes the rule ignore a violation would achieve the same effect. Eg we could tag the line with // NOPMD-NoUnnecessarySuppression or something like that, and then have UnnecessarySuppression look for this string and never report the line even if the suppression is unused...
The "right way" would be maybe to run PMD with JDK 8 classes in the aux-classpath during our build, so that CloseResource only sees the APIs that we can use...
This is fixed indeed by setting the right JRE classes as part of the -auxclasspath, this was intended back when we ensured these classes wouldn't collide in runtime and then we even implemented support for JRT (see #4628).
I'm unsure how we can do that through the Maven plugin 'though, as the auxclasspath is automatically populated from the project's dependencies…
Yes, that's a known problem. I wanted to create awareness first for this problem via #5299, but didn't have time to follow up. I guess, there is still one step missing in how we call PMD from maven-pmd-plugin. I don't know about gradle - I assume we have the same problem there. And the same for ant.
Although we claim, we have solved the dependency from runtime JDK with PMD 7, we actually didn't: you still need to make sure to run PMD with the same JDK as the version you compile for.
The actual problems if the JDK versions don't match up are actually seldom and very subtle (#4620 and now this one with AutoCloseable).
Activity
jsotuyod commentedon Nov 12, 2025
This is fixed indeed by setting the right JRE classes as part of the
-auxclasspath, this was intended back when we ensured these classes wouldn't collide in runtime and then we even implemented support for JRT (see #4628).I'm unsure how we can do that through the Maven plugin 'though, as the auxclasspath is automatically populated from the project's dependencies…
adangel commentedon Nov 13, 2025
Yes, that's a known problem. I wanted to create awareness first for this problem via #5299, but didn't have time to follow up. I guess, there is still one step missing in how we call PMD from maven-pmd-plugin. I don't know about gradle - I assume we have the same problem there. And the same for ant.
Although we claim, we have solved the dependency from runtime JDK with PMD 7, we actually didn't: you still need to make sure to run PMD with the same JDK as the version you compile for.
The actual problems if the JDK versions don't match up are actually seldom and very subtle (#4620 and now this one with AutoCloseable).
The "right" way to fix this is:
Alternatives and workarounds:
@SuppressWarningsand can suppress the violation in maven-pmd-plugin via https://github.com/pmd/pmd/blob/main/pmd-core/pmd-core-exclude-pmd.properties to not fail the build. The downside is, that it's easy to forget something in this file... (see Bump PMD from 7.17.0 to 7.18.0 #6197 (comment))jsotuyod commentedon Nov 13, 2025
Gradle can already handle this, by using the
pmdAuxconfiguration when setting these dependencies, such as:See https://docs.gradle.org/current/userguide/pmd_plugin.html#sec:pmd_dependency_management
Suppress CloseResource for ForkJoinPool
adangel commentedon Aug 20, 2026
Refs apache/maven-pmd-plugin#726