{"record":{"id":"20d338bba75181db","repo":"quarkusio/quarkus","slug":"failed-to-create-url-for-cached-resource-name","errorCode":null,"errorMessage":"Failed to create URL for cached resource: ${name}","messagePattern":"Failed to create URL for cached resource: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/AotRunnerClassLoader.java","lineNumber":215,"sourceCode":"\n        // For cached resources, return the stream directly without URL/URLConnection overhead\n        final byte[] data = serviceFiles.get(name);\n        if (data != null) {\n            return new ByteArrayInputStream(data);\n        }\n\n        if (isKnownAbsentResource(name)) {\n            return null;\n        }\n\n        return getParent().getResourceAsStream(name);\n    }\n\n    private URL createCachedResourceURL(String name, byte[] data) {\n        try {\n            return new URL(null, \"cached:\".concat(name), new CachedResourceURLStreamHandler(data));\n        } catch (MalformedURLException e) {\n            throw new RuntimeException(\"Failed to create URL for cached resource: \" + name, e);\n        }\n    }\n\n    /**\n     * URL stream handler for cached resources.\n     */\n    private static class CachedResourceURLStreamHandler extends URLStreamHandler {\n        private final byte[] data;\n\n        CachedResourceURLStreamHandler(byte[] data) {\n            this.data = data;\n        }\n\n        @Override\n        protected URLConnection openConnection(URL url) {\n            return new CachedResourceURLConnection(url, data);\n        }\n    }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/AotRunnerClassLoader.java#L197-L233","documentation":"AotRunnerClassLoader serves cached resources via synthetic 'cached:' URLs handled by CachedResourceURLStreamHandler. createCachedResourceURL wraps MalformedURLException in a RuntimeException; since the protocol string is a constant, this only fails if the URL cannot be constructed with the custom stream handler. The resulting error names the resource whose URL could not be created.","triggerScenarios":"getResource/findResource/getResources/findResources calling createCachedResourceURL when new URL(null, \"cached:\"+name, handler) throws MalformedURLException — practically only when the resource name makes the URL malformed or the 'cached:' protocol handler cannot be registered.","commonSituations":"Corrupted or unusual resource names coming from a damaged quarkus-application.dat cache, or JVM restrictions on custom URL stream handler factories.","solutions":["Rebuild the AOT package (mvn clean package) to regenerate a valid quarkus-application.dat cache.","Check the named resource entry in the cache for corruption or invalid characters.","Report/inspect if a java.net.URLStreamHandlerFactory installed elsewhere blocks the cached: protocol."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try (InputStream in = cl.getResourceAsStream(name)) {\n    // use resource\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to create URL for cached resource\")) {\n        throw new IllegalStateException(\"AOT cache corrupted; rebuild package\", e);\n    } throw e;\n}","preventionTips":["Regenerate the AOT cache after modifying packaged resources.","Verify cache file integrity when artifacts pass through artifact stores.","Avoid installing a global URLStreamHandlerFactory in the application."],"tags":["aot","classloader","resources","url"],"backgroundTag":"malformed-url","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"}