GeezerVison is showing github.com — [core] Fix #7240: Accept non-ASCII letters in Java binary and package names by xubenqiang · Pull Request #7244 · pmd/pmd
Conversation
xubenqiang
commented
Oct 26, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Describe the PR
PMD reports a processing error and skips the whole file when it imports a class whose name contains non-ASCII letters, e.g. import bar.Sample注文IF;, with IllegalArgumentException: Not a Java binary name. Java allows Unicode letters in identifiers (JLS §3.8), so such sources compile and should be analyzable.
The cause is in pmd-core's AssertionUtil: the three name patterns use \w, which only matches ASCII word characters unless Pattern.UNICODE_CHARACTER_CLASS is set. PACKAGE_PATTERN, BINARY_NAME_PATTERN and BINARY_NAME_NO_ARRAY now compile with that flag, so non-ASCII identifiers pass the sanity checks in TypeSystem, SymTableFactory and friends.
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)
Verification
mvn -pl pmd-core test -Dtest=AssertionUtilTest \
-Dmaven.javadoc.skip -Dcheckstyle.skip -Dpmd.skip -Djacoco.skip -Dspotbugs.skip
# Tests run: 3, Failures: 0, Errors: 0
- Red check with the
AssertionUtil change stashed: 2 of the 3 tests fail with IllegalArgumentException: Not a Java binary name 'Sample注文IF' and expected: <true> but was: <false> for the package name — the reported error.
- The new test covers binary names with and without array suffixes, a non-ASCII package name, and that names that are not identifiers (
"Sample 注文", "Sample注文IF;", "com. example") are still rejected.
- The
pmd-java module builds too, once the JVM uses UTF-8: on this Windows machine the default charset is cp936, and the JavaCC-generated sources failed to compile until -Dfile.encoding=UTF-8 was set (no LANG needed). mvn -pl pmd-java -am install -DskipTests -> BUILD SUCCESS. A PMD run on a source that imports bar.Sample注文IF (class on the auxclasspath) reports 0 processing errors; the failing path before the change is covered by the unit test above, which fails on the unfixed AssertionUtil.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Documentation Preview
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.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.
Regression Tester Report
(comment created at 2026-11-08 21:46:15+00:00 for 32b9389)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The fix is correct but is missing the customary docs/pages/release_notes.md "Fixed Issues" entry for #7240 expected by the project's convention.
No open issues 🎉
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Technically this allows class names that are not valid in Java (e.g. ⓕ matches \w, but can't be used in identifiers). On the other hand these assertions should be just simple sanity checks and Java compiler will pick those subtle differences, so this should be OK.
Building that module in this environment fails while compiling the JavaCC-generated JavaTokenKinds.java (the generated source is written with the platform encoding, so the compiler sees invalid characters on this machine).
Can you maybe explain which characters are wrong / what environment variables are affecting that? A build with LANG=C.UTF-8 LC_ALL=C.UTF-8 should pass for all modules.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the review. On the encoding question: it was the JVM's default charset, not LANG. This machine is Windows with a cp936 default charset, and the JavaCC-generated JavaTokenKinds.java contains characters that the compiler then mis-decodes ("illegal character"), so the module failed before compiling anything of mine. With the JVM told to use UTF-8 and the stale generation stamp removed so JavaCC actually regenerates, the module builds:
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8
mvn -pl pmd-java -am install -DskipTests -Dmaven.javadoc.skip -Dcheckstyle.skip -Dpmd.skip -Djacoco.skip -Dspotbugs.skip
# BUILD SUCCESS
So LANG=C.UTF-8 isn't needed on Windows; -Dfile.encoding=UTF-8 is what mattered. My earlier note about not being able to build pmd-java was wrong in the sense that it's fixable, and I've corrected it in the PR description.
On the pattern: agreed that this stays a sanity check. \w with UNICODE_CHARACTER_CLASS also accepts ⓕ-style code points, and as you say the compiler is the real authority for those. If you'd rather keep the assertion ASCII-only and instead widen only for the common non-ASCII identifier characters, I can switch to an explicit \p{javaJavaIdentifierPart}-based pattern with []/$ handling — say the word and I'll adjust.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
PACKAGE_PATTERN, BINARY_NAME_PATTERN and BINARY_NAME_NO_ARRAY matched with \w,
which only covers ASCII unless Pattern.UNICODE_CHARACTER_CLASS is set. A source
file that imports a class with a non-ASCII name (e.g. bar.Sample注文IF) failed the
sanity check with IllegalArgumentException: Not a Java binary name, so PMD skipped
the whole file.
Compile the three patterns with UNICODE_CHARACTER_CLASS and add a regression test
for binary names with and without array suffixes plus a non-ASCII package name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
And by the way, Copilot is wrong. There is no need for a submitter to update the release notes. Most LLMs get that part wrong anyway.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adangel
changed the title
[core] Accept non-ASCII letters in Java binary and package names
[core] Fix #7240: Accept non-ASCII letters in Java binary and package names
Nov 12, 2026
Reviewers
zbynek
zbynek approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|