Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/pmdPublic

(PoC) [java] Verify JDK API Version#5299

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
adangel wants to merge1 commit intopmd:main
base:main
Choose a base branch
Loading
fromadangel:poc/auxclasspath-jdk-version

Conversation

adangel
Copy link
Member

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 onhttps://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.

        <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#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?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

This is just a PoC to get the idea out. We should implement somethinglike this to warn users, if they execute PMD with incorrect javaversions. Using the wrong java version on the auxclasspath leadsto issues likepmd#4620 - the Java API changed between andtyperesolution works as designed. But with the wrong Java Runtimeon the auxclasspath, false positives are detected.You can specify the java runtime on the auxclasspath viaCLI as described onhttps://docs.pmd-code.org/latest/pmd_languages_java.html#providing-the-auxiliary-classpath .But if no java runtime is provided, we fall back to theruntime java version, which might or might not be correct.Note: For maven, there is currently no official way to configurethe java runtime onto the auxclasspath. You can workaround byadding 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 whenexecuting PMD, this adds the java 8 runtime and false positivessuch aspmd#4620 disappear.In theory, you could also use maven toolchains to execute PMDwith the correct java version.At the beginning I think, we should issue a warning, if wedetect a mismatch between the java language version and the javaversion, that we resolve from the auxclasspath. Note - thewarning I added in this PR only appears in DEBUG mode.And I assume (needs to be verified) that we could do this checkonce at the beginning and don't need to issue a warning forevery file...Once the warning is out there and we provided enough documentationaround how to resolve this warning, we could make this into afatal error, aborting the PMD analysis. We might even thinkabout not falling back to the runtime classpath for type resolution,forcing users to always configure the intended java versionexplicitly.
@ghost
Copy link

1 Message
📖Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Download full report as build artifact

Generated by 🚫Danger

adangel added a commit to adangel/pmd that referenced this pull requestJun 26, 2025
Refspmd#4291pmd#5299For now, the rule is disabled for this single class
adangel added a commit that referenced this pull requestJun 26, 2025
* Update build-tools from 30 to 32This enables the new rule UnnecessaryWarningSuppressionRefpmd/build-tools#74Ref#5803* Fix UnnecessaryWarningSuppression for missing overrideRefs#4291#5299For now, the rule is disabled for this single class
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@adangel

[8]ページ先頭

©2009-2025 Movatter.jp