{"record":{"id":"48daffa5335dedcc","repo":"apache/dubbo","slug":"resource-location-resourcelocation-is-neither","errorCode":null,"errorMessage":"Resource location [{resourceLocation}] is neither a URL not a well-formed file path","messagePattern":"Resource location \\[(.+?)\\] is neither a URL not a well-formed file path","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java","lineNumber":274,"sourceCode":"        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 {\n        try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {\n            byte[] buffer = new byte[1024];\n            int n;\n            while (-1 != (n = inputStream.read(buffer))) {\n                byteArrayOutputStream.write(buffer, 0, n);\n            }\n            return byteArrayOutputStream.toByteArray();\n        }\n    }\n}\n","sourceCodeStart":256,"sourceCodeEnd":291,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/IOUtils.java#L256-L291","documentation":"IOUtils.getURL treats a non-classpath location first as a URL, then as a file path. If both new URL(...) and new File(...).toURI().toURL() throw MalformedURLException, the location is neither a valid URL nor a usable file path and FileNotFoundException is thrown.","triggerScenarios":"Passing a malformed string that is not a classpath prefix, not a parseable URL (e.g. contains illegal characters/spaces without encoding), and not an existing/convertible file path.","commonSituations":"Unclosed URL protocols, Windows paths with backslashes, strings with spaces or special characters, or a path that does not exist on disk and cannot be expressed as a URL.","solutions":["URL-encode the location or pass a proper file:/http: URL","For local files, pass an absolute OS path that exists, or convert via new File(path).toURI().toURL() yourself first","Prefix classpath resources with the classpath: scheme handled earlier in the method"],"exampleFix":"// before\nURL u = IOUtils.getURL(\"C:\\\\my dir\\\\file.txt\");\n// after\nURL u = IOUtils.getURL(new File(\"C:\\\\my dir\\\\file.txt\").toURI().toString());","handlingStrategy":"validation","validationCode":"String loc = ...;\ntry { new java.net.URL(loc); /* ok */ }\ncatch (java.net.MalformedURLException e) {\n    java.io.File f = new java.io.File(loc);\n    if (!f.exists()) { /* will fail in getURL; resolve first */ }\n}","typeGuard":"static boolean isUrlOrFilePath(String s) {\n    try { new java.net.URL(s); return true; }\n    catch (Exception e) { return new java.io.File(s).exists(); }\n}","tryCatchPattern":"try { URL u = IOUtils.getURL(loc); }\ncatch (java.io.FileNotFoundException e) { /* neither URL nor file; encode or fix path */ }","preventionTips":["URL-encode paths with spaces/special characters","Prefer java.net.URI to construct valid URL strings"],"tags":["io","url","file","config"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}