Draft
Conversation
This is just a PoC to get the idea out. We should implement something like this to warn users, if they execute PMD with incorrect java versions. Using the wrong java version on the auxclasspath leads to issues like pmd#4620 - the Java API changed between and typeresolution works as designed. But with the wrong Java Runtime on the auxclasspath, false positives are detected. You can specify the java runtime on the auxclasspath via CLI as described on https://docs.pmd-code.org/latest/pmd_languages_java.html#providing-the-auxiliary-classpath . But if no java runtime is provided, we fall back to the runtime java version, which might or might not be correct. Note: For maven, there is currently no official way to configure the java runtime onto the auxclasspath. You can workaround by adding a system scoped dependency to your project, e.g. ```xml <dependency> <groupId>java8</groupId> <artifactId>java8-rt</artifactId> <version>8</version> <scope>system</scope> <systemPath>/path/to/jdk-8/jre/lib/rt.jar</systemPath> </dependency> ``` Since maven adds all project dependencies to the auxclasspath when executing PMD, this adds the java 8 runtime and false positives such as pmd#4620 disappear. In theory, you could also use maven toolchains to execute PMD with the correct java version. At the beginning I think, we should issue a warning, if we detect a mismatch between the java language version and the java version, that we resolve from the auxclasspath. Note - the warning I added in this PR only appears in DEBUG mode. And I assume (needs to be verified) that we could do this check once at the beginning and don't need to issue a warning for every file... Once the warning is out there and we provided enough documentation around how to resolve this warning, we could make this into a fatal error, aborting the PMD analysis. We might even think about not falling back to the runtime classpath for type resolution, forcing users to always configure the intended java version explicitly.
Generated by 🚫 Danger |
4 tasks
adangel
added a commit
that referenced
this pull request
Jun 26, 2025
* Update build-tools from 30 to 32 This enables the new rule UnnecessaryWarningSuppression Ref pmd/build-tools#74 Ref #5803 * Fix UnnecessaryWarningSuppression for missing override Refs #4291 #5299 For now, the rule is disabled for this single class
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the PR
This is just a PoC to get the idea out. We should implement something like this to warn users, if they execute PMD with incorrect java versions. Using the wrong java version on the auxclasspath leads to issues like #4620 - the Java API changed between and typeresolution works as designed. But with the wrong Java Runtime on the auxclasspath, false positives are detected.
You can specify the java runtime on the auxclasspath via CLI as described on https://docs.pmd-code.org/latest/pmd_languages_java.html#providing-the-auxiliary-classpath . But if no java runtime is provided, we fall back to the runtime java version, which might or might not be correct.
Note: For maven, there is currently no official way to configure the java runtime onto the auxclasspath. You can workaround by adding a system scoped dependency to your project, e.g.
Since maven adds all project dependencies to the auxclasspath when executing PMD, this adds the java 8 runtime and false positives such as #4620 disappear.
In theory, you could also use maven toolchains to execute PMD with the correct java version.
At the beginning I think, we should issue a warning, if we detect a mismatch between the java language version and the java version, that we resolve from the auxclasspath. Note - the warning I added in this PR only appears in DEBUG mode. And I assume (needs to be verified) that we could do this check once at the beginning and don't need to issue a warning for every file...
Once the warning is out there and we provided enough documentation around how to resolve this warning, we could make this into a fatal error, aborting the PMD analysis. We might even think about not falling back to the runtime classpath for type resolution, forcing users to always configure the intended java version explicitly.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)