PackageMatcher wildcards don't match package names with non-ASCII letters
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- java
- Domain
- testing-qa
Research direction
Start with PackageMatcher.java, especially the wildcard-to-regex conversion and pattern compilation cited in the issue. Add regression coverage for the listed matcher and slice checks using a package name with non-ASCII letters; done means the matcher recognizes it and the cycle check detects the cycle. A linked pull request is already open, so check its status before starting.
Written by the indexing model from the issue text.
Description
Package identifiers with wildcards don't match packages whose names contain non-ASCII letters, e.g. German umlauts. For slices().matching(..) this means that classes in such packages silently belong to no slice, so beFreeOfCycles() never sees their cycles. As long as other packages do match, failOnEmptyShould doesn't catch it either.
Reproduction
ArchUnit 1.4.2; PackageMatcher has only Javadoc changes since then, up to 1.5.1 and main.
package com.example.a; public class A { com.example.übersicht.B b; }
package com.example.übersicht; public class B { com.example.a.A a; }
| Check | Actual | Expected |
|---|---|---|
PackageMatcher.of("com.example.*").matches("com.example.übersicht") |
false |
true |
JavaClass.Predicates.resideInAPackage("com.example..") for B |
false |
true |
slices().matching("com.example.(*)..").should().beFreeOfCycles() |
0 cycles | 1 cycle |
slices().matching("com.example.(**)").should().beFreeOfCycles() |
0 cycles | 1 cycle |
The Javadoc says that * "stands for any non-empty sequence of characters but not the dot".
Cause
PackageMatcher turns the package identifier into a regular expression and uses \w for every wildcard (L81–L87, L162). For example, com.example.* becomes com\.example\.\w+.
The pattern is compiled without flags (L106), and then \w only matches a–z, A–Z, 0–9 and _. So übersicht fails at its very first letter and the package doesn't match, although Java allows any Unicode letter in package names.
Suggested fix
Compile the pattern with Pattern.UNICODE_CHARACTER_CLASS. With that flag patched into 1.4.2, all four checks above give the expected result. Alternatively, a character class closer to the Javadoc, such as "anything but a dot", would do.
Thanks for ArchUnit, we use it a lot.
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 350
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TNG/ArchUnit
-
beFreeOfCycles() misses cycles: TarjanComponentFinder does not return the component with the lowest node indexPossibly taken @StefanPenndorf claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
-
Constructor parameters added by the compiler (inner classes, enums) make `getParameters()` / `getParameterTypes()` inconsistent and misplace parameter annotationsPossibly taken @SamuelAdigos claimed this 2 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
breaking change
Difficulty 5/5 Over a week Newbie friendliness 18/100
TNG/ArchUnit#1756 · 1 comment ·
Maintainers usually reply within 1 day
-
breaking change
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsExceptionPossibly taken @jiteshkhatri11 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
javapathfinder/jpf-core#660 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
breaking change bug needs human review not ready priority medium size S
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
martin-francois/symphony-trello#1193 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day