Skip to content

Commit db84f2a

Browse files
wenytang-msCopilot
andcommitted
Fix findAnnotations() for standalone/fat Multi-Release JARs
NameLookup.findType() with ACCEPT_ANNOTATIONS may fail to resolve annotation types from standalone/fat Multi-Release JARs such as junit-platform-console-standalone-1.13.4.jar. This causes JUnit 5 test launches to fail with "Cannot find Testable on project build path". Add a fallback that retries with ACCEPT_ALL when the strict ACCEPT_ANNOTATIONS lookup finds nothing. The fallback still enforces access restrictions (checkRestrictions=true + isNonAccessible check) and verifies the resolved type is actually an annotation, so the PDE forbidden-transitive-dependency case remains protected. The fallback is skipped when the original lookup found the type but it was access-restricted, to avoid reviving forbidden dependencies. Fixes: #2959 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4951d4e commit db84f2a

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/util/CoreTestSearchEngine.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public static void findSuiteMethods(IJavaElement element, Set<IType> result, IPr
356356
private static IType findAnnotations(IJavaProject project, String... fullyQualifiedNames) throws JavaModelException {
357357
if (project instanceof JavaProject p) {
358358
NameLookup lookup= p.newNameLookup(DefaultWorkingCopyOwner.PRIMARY);
359+
boolean foundButRestricted= false;
359360
for (String fullyQualifiedName : fullyQualifiedNames) {
360361
NameLookup.Answer answer = lookup.findType(
361362
fullyQualifiedName,
@@ -365,8 +366,34 @@ private static IType findAnnotations(IJavaProject project, String... fullyQualif
365366
true /* wait for indexer */,
366367
true /* check restrictions */,
367368
null);
368-
if (answer != null && !answer.isNonAccessible()) {
369-
return answer.type;
369+
if (answer != null) {
370+
if (!answer.isNonAccessible()) {
371+
return answer.type;
372+
}
373+
foundButRestricted= true;
374+
}
375+
}
376+
// Fallback for standalone/fat JARs (e.g. junit-platform-console-standalone)
377+
// where NameLookup with ACCEPT_ANNOTATIONS may fail to resolve annotation
378+
// types from Multi-Release JARs. Retry with ACCEPT_ALL but still enforce
379+
// access restrictions and verify the resolved type is actually an annotation.
380+
// Only fall back when the type was genuinely not found, not when it was found
381+
// but restricted — to avoid reviving a forbidden transitive dependency.
382+
// See: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2959
383+
if (!foundButRestricted) {
384+
for (String fullyQualifiedName : fullyQualifiedNames) {
385+
NameLookup.Answer answer = lookup.findType(
386+
fullyQualifiedName,
387+
false /* no partial matches */,
388+
NameLookup.ACCEPT_ALL,
389+
false /* no secondary types */,
390+
true /* wait for indexer */,
391+
true /* check restrictions */,
392+
null);
393+
if (answer != null && !answer.isNonAccessible()
394+
&& answer.type != null && answer.type.isAnnotation()) {
395+
return answer.type;
396+
}
370397
}
371398
}
372399
}

0 commit comments

Comments
 (0)