quarkusio/quarkus · error · IOException
Failed to create an instance of java.nio.file.Path from <url
Error message
Failed to create an instance of java.nio.file.Path from <urlSpec>
What it means
urlSpecToPath converts a URL external form (e.g. file:/path or jar:file:...!/entry) to a java.nio.file.Path via Paths.get(URL.toURI()). If the URL/URI is malformed or the scheme has no filesystem provider, it throws IOException 'Failed to create an instance of java.nio.file.Path from <urlSpec>'.
Source
Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java:342
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
- URI-encode the URL spec (replace spaces with %20) before conversion
- Handle jar URLs specially: extract the jar file path before the '!/' separator and resolve the entry manually
- For non-file schemes, fetch the resource content instead of expecting a filesystem Path
- Check that the resource origin is a real file or jar on disk
Example fix
// before
Path p = Paths.get(new URL("file:/dir with space/x.jar").toURI()); // may fail upstream
// after
String spec = "file:/dir with space/x.jar".replace(" ", "%20");
Path p = Paths.get(new URI(spec)); Defensive patterns
Strategy: try-catch
Validate before calling
static boolean isFileUrl(String urlSpec) {
try {
URI u = new URI(urlSpec);
return "file".equals(u.getScheme()) || "jar".equals(u.getScheme());
} catch (URISyntaxException e) {
return false;
}
} Try / catch
try {
Path p = MojoUtils.getResourceOrigin(cl, name);
} catch (IOException e) {
log.warn("Cannot map {} to filesystem path (nested jar or remote URL?): {}", name, e.getMessage());
} Prevention
- URI-encode paths with spaces or special characters
- Avoid assuming every classpath origin is a filesystem path (nested jars, http)
- Handle jar:! URLs by splitting at '!/' before path conversion
- Test on platforms with spaces in default paths (macOS)
When it happens
Trigger: Called from getResourceOrigin when the resource URL cannot be converted to a URI/Path — e.g. jar URLs with nested '!/' entries (JAR-inside-JAR), URLs with spaces or illegal characters not encoded, or non-file schemes (http:, jrt:) without a provider.
Common situations: Spring Boot fat-jar style nested jars, unencoded spaces in paths (macOS 'Application Support'), resources served over http in exotic classloaders, running under GraalVM native image where jar protocol handling differs.
Related errors
- There were a problem while reading the resource dir '<name>'
- Failed to read %s
- Failed to read resources from classpath
- Could not read class path resources having path '${resourceP
- Failed to load + pomPropsPath + from the classpath
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/38c3750d4c8850bc.
Report an issue: GitHub.