quarkusio/quarkus · error · IOException
Failed to locate the origin of <name>
Error message
Failed to locate the origin of <name>
What it means
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.
Source
Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java:327
gavOut[2] = currentLine.substring(currentLine.indexOf('\'') + 1, currentLine.lastIndexOf('\''));
}
}
}
return gavOut;
}
/**
* Returns the JAR or the root directory that contains the class file that is on the
* classpath of the context classloader
*/
public static Path getClassOrigin(Class<?> cls) throws IOException {
return getResourceOrigin(cls.getClassLoader(), ClassLoaderHelper.fromClassNameToResourceName(cls.getName()));
}
public static Path getResourceOrigin(ClassLoader cl, final String name) throws IOException {
URL url = cl.getResource(name);
if (url == null) {
throw new IOException("Failed to locate the origin of " + name);
}
String classLocation = url.toExternalForm();
if (url.getProtocol().equals("jar")) {
classLocation = classLocation.substring(4, classLocation.length() - name.length() - 2);
} else {
classLocation = classLocation.substring(0, classLocation.length() - name.length());
}
return urlSpecToPath(classLocation);
}
private static Path urlSpecToPath(String urlSpec) throws IOException {
try {
return Paths.get(new URL(urlSpec).toURI());
} catch (Throwable e) {
throw new IOException(
"Failed to create an instance of " + Path.class.getName() + " from " + urlSpec, e);
}
}View on GitHub (pinned to e1c734241f)
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
Example fix
// before MojoUtils.getResourceOrigin(cl, "com.foo.Bar"); // dotted name // after MojoUtils.getResourceOrigin(cl, "com/foo/Bar.class");
Defensive patterns
Strategy: type-guard
Validate before calling
String resName = cls.getName().replace('.', '/') + ".class";
if (cls.getClassLoader() == null ? ClassLoader.getSystemResource(resName) == null
: cls.getClassLoader().getResource(resName) == null) {
throw new IllegalStateException("Resource not on classpath: " + resName);
} Type guard
static boolean isResolvable(ClassLoader cl, String name) {
return cl.getResource(name) != null;
} Try / catch
try {
Path origin = MojoUtils.getClassOrigin(cls);
} catch (IOException e) {
throw new IllegalStateException("Class " + cls.getName() + " not locatable via its classloader", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected : after attribute
- Failed to load CodeGenProvider class from deployment classlo
- Failed to index: ${className}, class not present in class lo
- Failed to locate the origin of ${name}
- Failed to read %s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/51314d7aaa0a4420.
Report an issue: GitHub.