{"record":{"id":"38c3750d4c8850bc","repo":"quarkusio/quarkus","slug":"failed-to-create-an-instance-of-java-nio-file-path","errorCode":null,"errorMessage":"Failed to create an instance of java.nio.file.Path from <urlSpec>","messagePattern":"Failed to create an instance of java\\.nio\\.file\\.Path from <urlSpec>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java","lineNumber":342,"sourceCode":"    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    }\n}\n","sourceCodeStart":324,"sourceCodeEnd":347,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java#L324-L347","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nPath p = Paths.get(new URL(\"file:/dir with space/x.jar\").toURI()); // may fail upstream\n// after\nString spec = \"file:/dir with space/x.jar\".replace(\" \", \"%20\");\nPath p = Paths.get(new URI(spec));","handlingStrategy":"try-catch","validationCode":"static boolean isFileUrl(String urlSpec) {\n    try {\n        URI u = new URI(urlSpec);\n        return \"file\".equals(u.getScheme()) || \"jar\".equals(u.getScheme());\n    } catch (URISyntaxException e) {\n        return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Path p = MojoUtils.getResourceOrigin(cl, name);\n} catch (IOException e) {\n    log.warn(\"Cannot map {} to filesystem path (nested jar or remote URL?): {}\", name, e.getMessage());\n}","preventionTips":["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)"],"tags":["classpath","url","path","io"],"backgroundTag":"url-to-path-conversion-failure","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"}