junit-team/junit5 · error · JUnitException
Failed to read contents of
Error message
Failed to read contents of ${reference}. What it means
JUnitException thrown by ModuleReferenceClassScanner.scan when ModuleReader.open() or reader.list() raises IOException while scanning a JPMS module for classes. The offending ModuleReference is in the message and the IOException is the cause.
Solutions
- Verify the module artifact opens cleanly: `jar tf <module>.jar` or `unzip -l`
- Rebuild the offending modular jar
- Check module-path permissions and storage reliability
- Move the artifact to local disk if scanning a remote mount
Defensive patterns
Strategy: try-catch
Try / catch
try {
// module classpath scanning
} catch (JUnitException e) {
if (e.getCause() instanceof IOException io) {
// inspect the module reference, repair the module path
}
} Prevention
- Validate modular jars in CI before test runs
- Prefer local, reliable storage for the module path
- Pin module-path entries explicitly rather than using broad globs
When it happens
Trigger: JPMS module classpath scanning where reading the module's contents fails - corrupt modular jar, broken module-path entry, IO error, or permission denial on the module artifact.
Common situations: Running tests on the module path (--module-path) with a corrupt or unreadable module; modular jar built incorrectly; module path pointing at a network resource that drops mid-scan.
Related errors
- Failed to close file system for
- Failed to create file system for
- Failed to load class with name
- Failed to load resource with name
- Error redirecting stderr to file
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/176a62bc970b5573.
Report an issue: GitHub.
Appendix: source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java:269
* Scan module reference for classes that potentially contain testable methods.
*/
List<Class<?>> scan(ModuleReference reference) {
try (ModuleReader reader = reference.open()) {
try (Stream<String> names = reader.list()) {
// @formatter:off
return names.filter(name -> !name.endsWith("/")) // remove directories
.map(Path::of)
.filter(SearchPathUtils::isClassOrSourceFile)
.map(SearchPathUtils::determineFullyQualifiedClassName)
.filter(classFilter::match)
.<Class<?>> map(this::loadClassUnchecked)
.filter(classFilter::match)
.toList();
// @formatter:on
}
}
catch (IOException e) {
throw new JUnitException("Failed to read contents of " + reference + ".", e);
}
}
/**
* Load class by its binary name.
*
* @see ClassLoader#loadClass(String)
*/
private Class<?> loadClassUnchecked(String binaryName) {
try {
return classLoader.loadClass(binaryName);
}
catch (ClassNotFoundException e) {
throw new JUnitException("Failed to load class with name '" + binaryName + "'.", e);
}
}
}View on GitHub (pinned to f070c699a0)