{"record":{"id":"e538f808205dc835","repo":"apache/dubbo","slug":"description-cannot-be-resolved-to-url-because-it","errorCode":null,"errorMessage":"{description} cannot be resolved to URL because it does not exist","messagePattern":"(.+?) cannot be resolved to URL because it does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java","lineNumber":262,"sourceCode":"        }\n        writeLines(new FileOutputStream(file, true), lines);\n    }\n\n    /**\n     * use like spring code\n     *\n     * @param resourceLocation\n     * @return\n     */\n    public static URL getURL(String resourceLocation) throws FileNotFoundException {\n        Assert.notNull(resourceLocation, \"Resource location must not be null\");\n        if (resourceLocation.startsWith(CommonConstants.CLASSPATH_URL_PREFIX)) {\n            String path = resourceLocation.substring(CommonConstants.CLASSPATH_URL_PREFIX.length());\n            ClassLoader cl = ClassUtils.getClassLoader();\n            URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path));\n            if (url == null) {\n                String description = \"class path resource [\" + path + \"]\";\n                throw new FileNotFoundException(description + \" cannot be resolved to URL because it does not exist\");\n            }\n            return url;\n        }\n        try {\n            // try URL\n            return new URL(resourceLocation);\n        } catch (MalformedURLException ex) {\n            // no URL -> treat as file path\n            try {\n                return new File(resourceLocation).toURI().toURL();\n            } catch (MalformedURLException ex2) {\n                throw new FileNotFoundException(\n                        \"Resource location [\" + resourceLocation + \"] is neither a URL not a well-formed file path\");\n            }\n        }\n    }\n\n    public static byte[] toByteArray(final InputStream inputStream) throws IOException {","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java#L244-L280","documentation":"IOUtils.getURL resolves a 'classpath:' prefixed resource location and, when the ClassLoader cannot find the resource on the classpath, throws FileNotFoundException with a descriptive class-path-resource message. The resource must exist at the exact path within the deployed JAR/classes directory.","triggerScenarios":"Calling IOUtils.getURL(\"classpath:\" + path) where path does not match any packaged resource; common with trailing slashes, wrong package separators, or resources excluded from the build artifact.","commonSituations":"Resource files not copied into target/classes by the build (missing src/main/resources placement or resources filtering); typo in the path; resource only present in a module not on the runtime classpath; fat-jar shading that relocated the file.","solutions":["Confirm the resource exists under target/classes or inside the JAR at the expected path","Use forward slashes and no leading slash in the classpath path argument","Ensure the resource is under src/main/resources and not excluded by maven `<resources>` configuration","If loading from another module, add it as a dependency so it lands on the classpath"],"exampleFix":"// before\nURL u = IOUtils.getURL(\"classpath:/config/app.yaml\");\n// after\nURL u = IOUtils.getURL(\"classpath:config/app.yaml\");","handlingStrategy":"validation","validationCode":"String path = \"config/app.yaml\";\nClassLoader cl = MyClass.class.getClassLoader();\nif (cl.getResource(path) == null) { /* missing on classpath; fix build before calling getURL */ }","typeGuard":"static boolean classpathResourceExists(String p) {\n    ClassLoader cl = Thread.currentThread().getContextClassLoader();\n    return (cl != null ? cl : ClassLoader.getSystemClassLoader()).getResource(p) != null;\n}","tryCatchPattern":"try { URL u = IOUtils.getURL(\"classpath:\" + path); }\ncatch (java.io.FileNotFoundException e) { /* resource not packaged; check build */ }","preventionTips":["Use forward slashes and no leading slash in classpath paths","Verify resources appear under target/classes in CI"],"tags":["io","classpath","resource","config"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}