quarkusio/quarkus · error · RuntimeException

Failed to create URL for cached resource: ${name}

Error message

Failed to create URL for cached resource: ${name}

What it means

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.

Source

Thrown at independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/AotRunnerClassLoader.java:215

        // For cached resources, return the stream directly without URL/URLConnection overhead
        final byte[] data = serviceFiles.get(name);
        if (data != null) {
            return new ByteArrayInputStream(data);
        }

        if (isKnownAbsentResource(name)) {
            return null;
        }

        return getParent().getResourceAsStream(name);
    }

    private URL createCachedResourceURL(String name, byte[] data) {
        try {
            return new URL(null, "cached:".concat(name), new CachedResourceURLStreamHandler(data));
        } catch (MalformedURLException e) {
            throw new RuntimeException("Failed to create URL for cached resource: " + name, e);
        }
    }

    /**
     * URL stream handler for cached resources.
     */
    private static class CachedResourceURLStreamHandler extends URLStreamHandler {
        private final byte[] data;

        CachedResourceURLStreamHandler(byte[] data) {
            this.data = data;
        }

        @Override
        protected URLConnection openConnection(URL url) {
            return new CachedResourceURLConnection(url, data);
        }
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Rebuild the AOT package (mvn clean package) to regenerate a valid quarkus-application.dat cache.
  2. Check the named resource entry in the cache for corruption or invalid characters.
  3. Report/inspect if a java.net.URLStreamHandlerFactory installed elsewhere blocks the cached: protocol.
Defensive patterns

Strategy: try-catch

Try / catch

try (InputStream in = cl.getResourceAsStream(name)) {
    // use resource
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Failed to create URL for cached resource")) {
        throw new IllegalStateException("AOT cache corrupted; rebuild package", e);
    } throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Corrupted or unusual resource names coming from a damaged quarkus-application.dat cache, or JVM restrictions on custom URL stream handler factories.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/20d338bba75181db. Report an issue: GitHub.