Skip to content

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

Merged
jsotuyod merged 1 commit intopmd:mainfrom
adangel:issue-1860
Oct 27, 2024
Merged

[ant] Formatter: avoid reflective access to determine console encoding#5286
jsotuyod merged 1 commit intopmd:mainfrom
adangel:issue-1860

Conversation

@adangel
Copy link
Copy Markdown
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
@ghost
Copy link
Copy Markdown

ghost commented Oct 25, 2024

1 Message
📖 No regression tested rules have been changed.

Generated by 🚫 Danger

@jsotuyod jsotuyod merged commit 4473aa6 into pmd:main Oct 27, 2024
@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

2 participants