junit-team/junit5 · error · JUnitException
Failed to load resource with name
Error message
Failed to load resource with name '${binaryName}'. What it means
JUnitException thrown by ModuleReferenceResourceScanner.loadResourceUnchecked when classLoader.getResource(binaryName) returns null OR the resource URL's URI is syntactically invalid. The resource was listed by the ModuleReader but cannot be resolved through the ClassLoader.
Solutions
- Ensure the module opens/contains the resource package to the test layer (opens directives or --add-opens)
- Sanitize resource names for URI safety
- Align the scanning ClassLoader with the module-aware loader
- Remove duplicate resources across split packages
Defensive patterns
Strategy: validation
Validate before calling
if (classLoader.getResource(name) == null) {
// skip or open the module so the resource is visible before scanning
} Prevention
- Use opens directives for resource packages scanned on the module path
- Validate resource names for URI safety
- Keep the test ClassLoader module-aware
When it happens
Trigger: ModuleReader lists a resource name, but classLoader.getResource(name) returns null (visibility/encapsulation), or the returned URL produces a URISyntaxException when converted.
Common situations: JPMS module encapsulation hiding the resource from the context ClassLoader; resource names with characters that break URI parsing; split-package resource conflicts; resources listed but not opened by the module.
Related errors
- Failed to load class with name
- Failed to read contents of
- Expected file name with file extension, but got
- Failed to close file system for
- Failed to create file system for
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/7958594a292ca2bb.
Report an issue: GitHub.
Appendix: source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java:329
return names.filter(name -> !name.endsWith(".class"))
.map(this::loadResourceUnchecked)
.filter(resourceFilter::match)
.toList();
// @formatter:on
}
}
catch (IOException e) {
throw new JUnitException("Failed to read contents of " + reference + ".", e);
}
}
private Resource loadResourceUnchecked(String binaryName) {
try {
URI uri = requireNonNull(classLoader.getResource(binaryName)).toURI();
return Resource.of(binaryName, uri);
}
catch (NullPointerException | URISyntaxException e) {
throw new JUnitException("Failed to load resource with name '" + binaryName + "'.", e);
}
}
}
private ModuleUtils() {
}
}
View on GitHub (pinned to f070c699a0)