{"record":{"id":"efa44301c4ff1f30","repo":"alibaba/nacos","slug":"getdescription-cannot-be-opened-because-it-doe","errorCode":null,"errorMessage":"{getDescription()} cannot be opened because it does not exist","messagePattern":"(.+?) cannot be opened because it does not exist","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/nacos/common/packagescan/resource/ClassPathResource.java","lineNumber":199,"sourceCode":"\n    /**\n     * This implementation opens an InputStream for the given class path resource.\n     *\n     * @see ClassLoader#getResourceAsStream(String)\n     * @see Class#getResourceAsStream(String)\n     */\n    @Override\n    public InputStream getInputStream() throws IOException {\n        InputStream is;\n        if (this.clazz != null) {\n            is = this.clazz.getResourceAsStream(this.path);\n        } else if (this.classLoader != null) {\n            is = this.classLoader.getResourceAsStream(this.path);\n        } else {\n            is = ClassLoader.getSystemResourceAsStream(this.path);\n        }\n        if (is == null) {\n            throw new FileNotFoundException(getDescription() + \" cannot be opened because it does not exist\");\n        }\n        return is;\n    }\n\n    /**\n     * This implementation returns a URL for the underlying class path resource,\n     * if available.\n     *\n     * @see ClassLoader#getResource(String)\n     * @see Class#getResource(String)\n     */\n    @Override\n    public URL getUrl() throws IOException {\n        URL url = resolveUrl();\n        if (url == null) {\n            throw new FileNotFoundException(getDescription() + \" cannot be resolved to URL because it does not exist\");\n        }\n        return url;","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/packagescan/resource/ClassPathResource.java#L181-L217","documentation":"ClassPathResource.getInputStream() resolves the resource via the class loader, the owning Class, or the system loader in turn, and throws FileNotFoundException (with a human-readable description) when every loader returns null. It indicates the configured path simply is not present on the classpath at runtime.","triggerScenarios":"Constructing a ClassPathResource with a path that the JVM classloader cannot locate, then calling getInputStream(). The path is resolved relative to the class root; a leading slash or wrong separator changes the lookup root and can cause a miss.","commonSituations":"Loading a bundled config or certificate from a JAR whose packaging (shade/assembly) excluded or relocated the file. Referencing `com/example/foo.properties` when the resource sits under `META-INF/`. Running in a fat-jar or module layer where the resource is on a non-delegated loader. Typo in the path, or a leading `/` that shifts the lookup from class-relative to classloader-relative.","solutions":["Verify the resource physically exists inside the deployed JAR (`jar tf app.jar | grep <path>`) or on the classpath directory.","Correct the path: drop or add a leading `/` depending on whether you want class-relative or loader-relative resolution; normalize separators to `/`.","If using a fat/shaded JAR, adjust the assembly or shade plugin to include the resource file in the build output.","Pass an explicit Class or ClassLoader whose visibility covers the resource instead of relying on the system loader fallback."],"exampleFix":"// before — path does not exist on classpath\nResource r = new ClassPathResource(\"config/app.yml\");\nInputStream in = r.getInputStream(); // throws\n\n// after — correct path under classpath root\nResource r = new ClassPathResource(\"META-INF/config/app.yml\");","handlingStrategy":"validation","validationCode":"static InputStream openIfExists(ClassPathResource r) throws IOException {\n    if (!r.exists()) {\n        throw new FileNotFoundException(\n            \"Missing classpath resource: \" + r.getPath() + \" — verify packaging/path\");\n    }\n    return r.getInputStream();\n}","typeGuard":null,"tryCatchPattern":"try {\n    InputStream in = resource.getInputStream();\n} catch (FileNotFoundException fnf) {\n    // log the description, fall back to a default resource, or fail fast\n    throw fnf;\n}","preventionTips":["Call ClassPathResource.exists() before getInputStream().","Verify resources are included in the build output (`jar tf`).","Normalize paths to use `/` separators and check leading-slash semantics."],"tags":["classpath","resource","io","filenotfound","packaging"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}