Copilot commented on code in PR #3554:
URL: https://github.com/apache/maven-surefire/pull/3554#discussion_r4561313278
##########
surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java:
##########
@@ -346,7 +369,16 @@ private boolean matchClassPatter(String testClassFile) {
classPattern = classPattern.replace('/', separatorChar);
}
- if (classPattern.endsWith(WILDCARD_FILENAME_POSTFIX) ||
classPattern.endsWith(CLASS_FILE_EXTENSION)) {
+ String packagePostfix = WILDCARD_PACKAGE_POSTFIX.replace('/',
separatorChar);
+ if (classPattern.endsWith(packagePostfix)) {
+ // The source pattern was ambiguous between a package and a
class name (see
+ // isPackageName); also match the legacy single-class-file
interpretation, so a class
+ // whose name happens to start with a lowercase letter still
matches itself.
+ String legacyClassPattern = classPattern.substring(0,
classPattern.length() - packagePostfix.length())
+ + WILDCARD_FILENAME_POSTFIX;
+ return of(classPattern,
legacyClassPattern).matches(testClassFile, true);
Review Comment:
The legacy fallback is currently enabled for any pattern ending with `/*`,
but not all such patterns are ambiguous (e.g., user-supplied slash patterns
like `dev/aspectj/*`). This can cause unintended extra matches such as also
matching `dev/aspectj.class` via the generated legacy pattern `dev/aspectj.*`.
Consider gating the legacy fallback on an explicit flag that indicates the
pattern originated from the dotted `pkg.*` ambiguity resolution (e.g., store
this on `ResolvedTest` when `fromFullyQualifiedClass()` chooses the package
interpretation), and only then add `legacyClassPattern`.
##########
surefire-api/src/main/java/org/apache/maven/surefire/api/testset/ResolvedTest.java:
##########
@@ -346,7 +369,16 @@ private boolean matchClassPatter(String testClassFile) {
classPattern = classPattern.replace('/', separatorChar);
}
- if (classPattern.endsWith(WILDCARD_FILENAME_POSTFIX) ||
classPattern.endsWith(CLASS_FILE_EXTENSION)) {
+ String packagePostfix = WILDCARD_PACKAGE_POSTFIX.replace('/',
separatorChar);
+ if (classPattern.endsWith(packagePostfix)) {
+ // The source pattern was ambiguous between a package and a
class name (see
+ // isPackageName); also match the legacy single-class-file
interpretation, so a class
+ // whose name happens to start with a lowercase letter still
matches itself.
+ String legacyClassPattern = classPattern.substring(0,
classPattern.length() - packagePostfix.length())
+ + WILDCARD_FILENAME_POSTFIX;
+ return of(classPattern,
legacyClassPattern).matches(testClassFile, true);
Review Comment:
Given the broadened matching behavior when `classPattern` ends with `/*`,
add a regression test that ensures an explicit package pattern (e.g.
`dev/aspectj/*`) does NOT match a sibling class file like `dev/aspectj.class`.
This would catch the unintended inclusion caused by the legacy fallback and
protect the semantics of unambiguous slash-form package patterns.
--
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]