{"record":{"id":"7958594a292ca2bb","repo":"junit-team/junit5","slug":"failed-to-load-resource-with-name-binaryname","errorCode":null,"errorMessage":"Failed to load resource with name '${binaryName}'.","messagePattern":"Failed to load resource with name '(.+?)'\\.","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java","lineNumber":329,"sourceCode":"\t\t\t\t\treturn names.filter(name -> !name.endsWith(\".class\"))\n\t\t\t\t\t\t\t.map(this::loadResourceUnchecked)\n\t\t\t\t\t\t\t.filter(resourceFilter::match)\n\t\t\t\t\t\t\t.toList();\n\t\t\t\t\t// @formatter:on\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tthrow new JUnitException(\"Failed to read contents of \" + reference + \".\", e);\n\t\t\t}\n\t\t}\n\n\t\tprivate Resource loadResourceUnchecked(String binaryName) {\n\t\t\ttry {\n\t\t\t\tURI uri = requireNonNull(classLoader.getResource(binaryName)).toURI();\n\t\t\t\treturn Resource.of(binaryName, uri);\n\t\t\t}\n\t\t\tcatch (NullPointerException | URISyntaxException e) {\n\t\t\t\tthrow new JUnitException(\"Failed to load resource with name '\" + binaryName + \"'.\", e);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tprivate ModuleUtils() {\n\t}\n\n}\n","sourceCodeStart":311,"sourceCodeEnd":339,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java#L311-L339","documentation":"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.","triggerScenarios":"ModuleReader lists a resource name, but classLoader.getResource(name) returns null (visibility/encapsulation), or the returned URL produces a URISyntaxException when converted.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (classLoader.getResource(name) == null) {\n    // skip or open the module so the resource is visible before scanning\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use opens directives for resource packages scanned on the module path","Validate resource names for URI safety","Keep the test ClassLoader module-aware"],"tags":["classpath-scanning","resources","jpms","encapsulation"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}