A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/eclipse-pmd/eclipse-pmd/issues/316 below:

PMD not using the correct java runtime for the project · Issue #316 · eclipse-pmd/eclipse-pmd · GitHub

The tl;dr of this is that eclipse-pmd should use the runtime that is selected for the project rather than using the default runtime that happens to be executing eclipse. Everything under here is just evidence and justification.

I am running eclipse 4.34.0.20241128-0756, eclipse-pmd Core 4.6.0.202503291637, and eclipse-pmd Java Support 4.6.0.202503291637. I have been doing the bulk of my evaluation and remediation of PMD issues in our codebase using the command line tool. Once the codebase is clean, my goal is to have my whole team use the eclipse-pmd plugin. As such I'm very aware of any differences between the output of the command line tool and the plugin.

I am having a specific issue with the errorprone/CloseResource rule. When I run it from the command line, I get no violations. When I run it from Eclipse, I get four violations (involving 3 classes).

I believe what is happening is that even though my projects are marked as using the java17 run time, eclipse-pmd is using the default runtime of whatever java is running eclipse. My command line pmd executions are running under java17. Eclipse itself is running under java21. CloseResource in Eclipse reports ThreadPoolExecutor, ExecutorService, and HttpClient. Each of these libraries did not inherit AutoCloseable in 17 and does inherit it in 21:

See https://pmd.github.io/pmd/pmd_languages_java.html#providing-the-auxiliary-classpath for discussion of how and why alternate runtimes can be provided.

To further prove this, I ran pmd from the command line as shown in the following matrix:

serial     auxClasspath        use-version       java
1          empty               17                17
2          empty               17                21
3          17-rt               17                17
4          17-rt               17                21

Serials 1, 3, and 4 produced no output, which is what I expected. Serial 2 produced the same 4 CloseResource errors that eclipse-pmd produces, indicating that my analysis is correct - eclipse-pmd is not using the project's selected runtime.

To be honest, now that I understand this it's not a huge deal, I can just ignore them with a comment to handle when we upgrade java, but it given that projects explicitly set the java version, it seems to make sense that eclipse-pmd would honor it while evaluating.

Thanks for the plugin!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4