{"record":{"id":"e80c56abd05c51b6","repo":"OpenAPITools/openapi-generator","slug":"exception-while-listing-files-in-spec-root-directo","errorCode":null,"errorMessage":"Exception while listing files in spec root directory: %s","messagePattern":"Exception while listing files in spec root directory: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/config/MergedSpecBuilder.java","lineNumber":833,"sourceCode":"                adder.accept(name, value);\n            }\n        });\n    }\n\n    private List<String> getAllSpecFilesInDirectory() {\n        Path rootDirectory = new File(inputSpecRootDirectory).toPath();\n        try (Stream<Path> pathStream = Files.walk(rootDirectory)) {\n            return pathStream\n                    .filter(path -> !Files.isDirectory(path))\n                    .filter(path -> {\n                        String name = path.getFileName().toString().toLowerCase(Locale.ROOT);\n                        return SPEC_EXTENSIONS.stream().anyMatch(name::endsWith);\n                    })\n                    .map(path -> rootDirectory.relativize(path).toString())\n                    .sorted()\n                    .collect(Collectors.toList());\n        } catch (IOException e) {\n            throw new RuntimeException(\"Exception while listing files in spec root directory: \" + inputSpecRootDirectory, e);\n        }\n    }\n\n    private void deleteMergedFileFromPreviousRun() {\n        String targetDir = (outputDirectory != null) ? outputDirectory : inputSpecRootDirectory;\n        try {\n            Files.deleteIfExists(Paths.get(targetDir + File.separator + mergeFileName + \".json\"));\n        } catch (IOException ignored) {\n        }\n        try {\n            Files.deleteIfExists(Paths.get(targetDir + File.separator + mergeFileName + \".yaml\"));\n        } catch (IOException ignored) {\n        }\n    }\n}\n","sourceCodeStart":815,"sourceCodeEnd":849,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/MergedSpecBuilder.java#L815-L849","documentation":"MergedSpecBuilder wraps an IOException from Files.walk while enumerating spec files under inputSpecRootDirectory during directory merge mode. The generator cannot start reading specs because the root directory does not exist, cannot be traversed, or an I/O error occurs mid-walk.","triggerScenarios":"--input-spec (inputSpecRootDirectory) points at a path that does not exist (NoSuchFileException), a path with no traverse/read permission for the process, a broken symlink, or a filesystem error while streaming the directory tree.","commonSituations":"Relative path resolved from a different working directory in CI; typo in the --input-spec value; directory deleted between build steps; containerized run where the volume is not mounted at the expected path or the user lacks read permission.","solutions":["Verify the spec root directory exists and the path is spelled correctly; prefer an absolute path in scripts and CI.","Run the generator from the directory the relative path was designed for, or fix the working directory configuration.","Ensure the executing user has read and traverse (execute) permission on the directory and its parents, especially in Docker."],"exampleFix":"# before:\nopenapi-generator-cli generate -i ./openapi-specs -g java --additional-properties=mergeMode=deep\n# after (absolute path, verified):\nopenapi-generator-cli generate -i /home/ci/pipeline/openapi-specs -g java --additional-properties=mergeMode=deep","handlingStrategy":"validation","validationCode":"// Pre-flight: verify the spec root is a readable directory before generating\nimport java.nio.file.*;\n\nPath root = Paths.get(inputSpecRootDirectory);\nif (!Files.isDirectory(root))\n    throw new IllegalArgumentException(\"Spec root directory does not exist: \" + root.toAbsolutePath());\nif (!Files.isReadable(root))\n    throw new IllegalArgumentException(\"Spec root directory is not readable: \" + root.toAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n    List<String> specs = readAllSpecFiles(); // wraps the Files.walk failure\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Exception while listing files in spec root directory\")) {\n        // log the absolute expected path and the CI user, then fail the build with a clear hint\n        throw new BuildException(\"Check --input-spec path and permissions: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Use absolute spec paths in CI pipelines; relative paths resolve against whatever the runner's working directory is.","Fail fast in wrapper scripts: assert the directory exists before invoking the generator.","In containers, verify the spec volume is mounted and the runtime user can read it."],"tags":["openapi","spec-merge","filesystem","io","input-spec"],"backgroundTag":"directory-not-found","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}