adangel opened a new pull request, #726:
URL: https://github.com/apache/maven-pmd-plugin/pull/726

   This change improves the correctness of PMD violations: For type resolution, 
PMD loads the classes to see the available type hierarchy, methods, return 
types etc. The project's dependencies are already provided to PMD by the plugin 
with the aux classpath. But the Java platform classes where still resolved from 
the current Java runtime. This can lead for specific cases in either false 
positives or false negatives. Examples are: `ExecutorService` is 
`AutoCloseable` since Java 19. If maven/PMD is executed with Java 25 but the 
target is Java 17, then PMD's CloseResource would wrongly suggest to use 
try-with-resources for ExecutorServices. Another example is `ByteBuffer#flip`: 
In Java 8, it returns `Buffer` (inherited), in Java 9+ it returns `ByteBuffer`. 
In Java 8, one must cast, in Java 9, the cast might be unnecessary, triggering 
PMD's UnnecessaryCast rule.
   
   Historically, PMD 6.x loaded the types via reflection from a custom 
classloader - so it was not able to load classes from newer runtimes then it 
was running at. Hence the solution with the toolchains (MPMD-304 #277). With 
PMD 7, the classes are loaded via ASM, which allows to decouple the Java 
version used for executing PMD (runtime) from the Java version of the project 
under analysis (targetJdk). Since PMD 7, PMD running under Java 8 can analyze 
e.g. Java 25 projects. But one crucial step was missing: The Java platform 
classes.
   
   To resolve Java platform classes, PMD by default used the current runtime. 
With the next PMD version 7.27.0, we'll log a warning, if this happens.
   
   This change prepares for that and tries to add the correct Java platform 
classes to the aux classpath for PMD.
   
   Note: This change is independent of the PMD version. Providing the 
jrt-fs.jar or rt.jar on the aux classpath was supported since PMD 7.0.0, but 
just not used. The only change in PMD 7.27.0 in that regard is, that a warning 
is logged, if neither jrt-fs.jar or rt.jar is found on the aux classpath.
   
   -----
   
   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
   - [x] Your pull request should address just one issue, without pulling in 
other changes.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body.
     Note that commits might be squashed by a maintainer on merge.
   - [ ] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied.
     This may not always be possible but is a best-practice.
   - [x] Run `mvn verify` to make sure basic checks pass.
     A more thorough check will be performed on your pull request automatically.
   - [x] You have run the integration tests successfully (`mvn -Prun-its 
verify`).
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License 
Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [x] I hereby declare this contribution to be licenced under the [Apache 
License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to