{"record":{"id":"51314d7aaa0a4420","repo":"quarkusio/quarkus","slug":"failed-to-locate-the-origin-of-name-51314d","errorCode":null,"errorMessage":"Failed to locate the origin of <name>","messagePattern":"Failed to locate the origin of <name>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java","lineNumber":327,"sourceCode":"                    gavOut[2] = currentLine.substring(currentLine.indexOf('\\'') + 1, currentLine.lastIndexOf('\\''));\n                }\n            }\n        }\n        return gavOut;\n    }\n\n    /**\n     * Returns the JAR or the root directory that contains the class file that is on the\n     * classpath of the context classloader\n     */\n    public static Path getClassOrigin(Class<?> cls) throws IOException {\n        return getResourceOrigin(cls.getClassLoader(), ClassLoaderHelper.fromClassNameToResourceName(cls.getName()));\n    }\n\n    public static Path getResourceOrigin(ClassLoader cl, final String name) throws IOException {\n        URL url = cl.getResource(name);\n        if (url == null) {\n            throw new IOException(\"Failed to locate the origin of \" + name);\n        }\n        String classLocation = url.toExternalForm();\n        if (url.getProtocol().equals(\"jar\")) {\n            classLocation = classLocation.substring(4, classLocation.length() - name.length() - 2);\n        } else {\n            classLocation = classLocation.substring(0, classLocation.length() - name.length());\n        }\n        return urlSpecToPath(classLocation);\n    }\n\n    private static Path urlSpecToPath(String urlSpec) throws IOException {\n        try {\n            return Paths.get(new URL(urlSpec).toURI());\n        } catch (Throwable e) {\n            throw new IOException(\n                    \"Failed to create an instance of \" + Path.class.getName() + \" from \" + urlSpec, e);\n        }\n    }","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java#L309-L345","documentation":"MojoUtils.getResourceOrigin throws IOException when the given ClassLoader cannot locate the requested resource name via cl.getResource(name), i.e. the resource is not on the classpath. getClassOrigin uses it to resolve where a class file lives.","triggerScenarios":"Calling getResourceOrigin(cl, name) (or getClassOrigin(cls)) for a class/resource not visible to the provided ClassLoader — wrong loader, resource name typo, class generated at runtime but never written to a locatable location.","commonSituations":"Passing an application ClassLoader for a JDK/bootstrap class, resource path not converted to slash-separated form, shaded jars excluding the resource, mismatched classloader in modular or native-image environments.","solutions":["Ensure the resource name is in classpath form (e.g. com/foo/Bar.class, not com.foo.Bar)","Use the ClassLoader that actually loaded the class: cls.getClassLoader() (fall back to the system CL if null)","Verify the resource exists in the jar/directory on the classpath (unzip -l / ls)","Check that build shading/exclusion rules do not strip the resource"],"exampleFix":"// before\nMojoUtils.getResourceOrigin(cl, \"com.foo.Bar\"); // dotted name\n// after\nMojoUtils.getResourceOrigin(cl, \"com/foo/Bar.class\");","handlingStrategy":"type-guard","validationCode":"String resName = cls.getName().replace('.', '/') + \".class\";\nif (cls.getClassLoader() == null ? ClassLoader.getSystemResource(resName) == null\n        : cls.getClassLoader().getResource(resName) == null) {\n    throw new IllegalStateException(\"Resource not on classpath: \" + resName);\n}","typeGuard":"static boolean isResolvable(ClassLoader cl, String name) {\n    return cl.getResource(name) != null;\n}","tryCatchPattern":"try {\n    Path origin = MojoUtils.getClassOrigin(cls);\n} catch (IOException e) {\n    throw new IllegalStateException(\"Class \" + cls.getName() + \" not locatable via its classloader\", e);\n}","preventionTips":["Convert class names to resource names (dots to slashes + .class) before lookup","Use the exact classloader that loaded the class","Verify jar packaging rules do not exclude the resource","Be aware bootstrap (null) classloaders need special handling"],"tags":["classpath","classloader","resource"],"backgroundTag":"classpath-resource-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}