Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ant] Formatter: avoid reflective access to determine console encoding #5286

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

adangel
Copy link
Member

@adangel adangel commented Oct 25, 2024

Describe the PR

  • for java 17+, there is public API to get the console encoding -> no problem
  • for older java versions, try to use system property sun.jnu.encoding if it exists
  • only then use the fall-backs with illegal reflective access to private fields/methods on java.io.Console
  • Also avoid using reflection utils from apache commons, instead use reflection directly. The illegal access warnings are then properly reported against our class net.sourceforge.pmd.ant.Formatter.

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)

- for java 17+, there is public API to get the console encoding
  -> no problem
- for older java versions, try to use system property
  sun.jnu.encoding if it exists
- only then use the fall-backs with illegal reflective access
  to private fields/methods on java.io.Console
- Also avoid using reflection utils from apache commons, instead
  use reflection directly. The illegal access warnings are then
  properly reported against our class
  net.sourceforge.pmd.ant.Formatter.

Fixes pmd#1860
@adangel adangel added this to the 7.8.0 milestone Oct 25, 2024
@pmd-test
Copy link

1 Message
📖 No regression tested rules have been changed.

Generated by 🚫 Danger

@jsotuyod jsotuyod merged commit 4473aa6 into pmd:main Oct 27, 2024
3 checks passed
@adangel adangel deleted the issue-1860 branch November 22, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ant] Reflective access warnings on java > 9 and java < 17
3 participants