{"record":{"id":"e43bde30ecf2e40e","repo":"junit-team/junit5","slug":"failed-to-load-class-with-name-binaryname","errorCode":null,"errorMessage":"Failed to load class with name '${binaryName}'.","messagePattern":"Failed to load class 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":283,"sourceCode":"\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\t/**\n\t\t * Load class by its binary name.\n\t\t *\n\t\t * @see ClassLoader#loadClass(String)\n\t\t */\n\t\tprivate Class<?> loadClassUnchecked(String binaryName) {\n\t\t\ttry {\n\t\t\t\treturn classLoader.loadClass(binaryName);\n\t\t\t}\n\t\t\tcatch (ClassNotFoundException e) {\n\t\t\t\tthrow new JUnitException(\"Failed to load class with name '\" + binaryName + \"'.\", e);\n\t\t\t}\n\t\t}\n\n\t}\n\n\t/**\n\t * {@link ModuleReference} resource class scanner.\n\t *\n\t * @since 1.11\n\t */\n\tstatic class ModuleReferenceResourceScanner {\n\n\t\tprivate final ResourceFilter resourceFilter;\n\t\tprivate final ClassLoader classLoader;\n\n\t\tModuleReferenceResourceScanner(ResourceFilter resourceFilter, ClassLoader classLoader) {\n\t\t\tthis.resourceFilter = resourceFilter;\n\t\t\tthis.classLoader = classLoader;","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java#L265-L301","documentation":"JUnitException thrown by ModuleReferenceClassScanner.loadClassUnchecked when ClassLoader.loadClass(binaryName) throws ClassNotFoundException. The class file was visible to the module scanner but the runtime ClassLoader cannot resolve it to a Class object.","triggerScenarios":"Module scanning finds a class file (e.g. com/foo/Bar.class) and derives binary name com.foo.Bar, but classLoader.loadClass(\"com.foo.Bar\") fails - classloader visibility gap, missing dependency, or binary-name/path mismatch (nested classes, shading, module encapsulation).","commonSituations":"JPMS module does not export or contain the package to the test classloader; shaded or relocated classes whose file path no longer matches their binary name; orphan .class files left in a module; split packages across modules.","solutions":["Ensure the module exports/contains the package to the test layer","Remove orphan or stale .class files from the module","Rebuild after relocation/shading so paths match binary names","Align the scanning ClassLoader with the runtime ClassLoader"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep module exports aligned with packages that contain test classes","Clean build outputs before packaging modules to avoid orphan .class files","Avoid relocation/shading that breaks the path-to-binary-name mapping"],"tags":["classpath-scanning","classloader","jpms"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}