Skip to content

Commit e123ed6

Browse files
committed
Protect against potential problems when converting selectors to sources
1 parent 3502b7a commit e123ed6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/DiscoveryIssueCollector.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void selectorProcessed(UniqueId engineId, DiscoverySelector selector, Sel
6767
if (result.getStatus() == FAILED) {
6868
this.issues.add(DiscoveryIssue.builder(Severity.ERROR, selector + " resolution failed") //
6969
.cause(result.getThrowable()) //
70-
.source(toSource(selector)) //
70+
.source(toSourceSafely(selector)) //
7171
.build());
7272
}
7373
else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelector uniqueIdSelector) {
@@ -78,7 +78,17 @@ else if (result.getStatus() == UNRESOLVED && selector instanceof UniqueIdSelecto
7878
}
7979
}
8080

81-
static @Nullable TestSource toSource(DiscoverySelector selector) {
81+
private static @Nullable TestSource toSourceSafely(DiscoverySelector selector) {
82+
try {
83+
return toSource(selector);
84+
}
85+
catch (Exception e) {
86+
logger.error(e, () -> "Failed to convert DiscoverySelector [%s] into TestSource".formatted(selector));
87+
return null;
88+
}
89+
}
90+
91+
private static @Nullable TestSource toSource(DiscoverySelector selector) {
8292
if (selector instanceof ClassSelector classSelector) {
8393
return ClassSource.from(classSelector.getClassName());
8494
}

0 commit comments

Comments
 (0)