{"record":{"id":"cb29a1030226c718","repo":"alibaba/spring-ai-alibaba","slug":"got-error-when-creating-files-cb29a1","errorCode":null,"errorMessage":"Got error when creating files","messagePattern":"Got error when creating files","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/utils/ContributorFileUtil.java","lineNumber":70,"sourceCode":"\t\tPath resourceFile = projectRoot.resolve(\"src/main/resources\").resolve(fileName);\n\t\ttry {\n\t\t\tFiles.copy(inputStream, resourceFile);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tpublic static Path createDirectory(Path projectRoot, ProjectDescription projectDescription) {\n\t\tStringBuilder pathBuilder = new StringBuilder(\"src/main/\").append(projectDescription.getLanguage().id());\n\t\tString packagePath = projectDescription.getPackageName().replace('.', '/');\n\t\tpathBuilder.append(\"/\").append(packagePath).append(\"/graph/\");\n\t\tPath fileRoot;\n\t\ttry {\n\t\t\tfileRoot = Files.createDirectories(projectRoot.resolve(pathBuilder.toString()));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Got error when creating files\", e);\n\t\t}\n\t\treturn fileRoot;\n\t}\n\n}\n","sourceCodeStart":52,"sourceCodeEnd":76,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/utils/ContributorFileUtil.java#L52-L76","documentation":"ContributorFileUtil.createDirectory creates <projectRoot>/<packagePath>/graph/ for generated source files and wraps any failure (IOException, security, invalid path) in RuntimeException(\"Got error when creating files\") with the cause attached.","triggerScenarios":"Files.createDirectories fails — parent projectRoot doesn't exist or is a file, insufficient filesystem permissions, invalid characters in packagePath, or disk full.","commonSituations":"Generating into a read-only directory (CI containers); project root path typo; package path containing illegal characters derived from names; running as a user without write access to the target.","solutions":["Check the cause (e.getCause()) to identify the underlying filesystem error","Ensure projectRoot exists, is a writable directory, and the process user has write permission","Sanitize packagePath of illegal filesystem characters before generation","Verify disk space and path length limits"],"exampleFix":"// before\nPath root = Files.createDirectories(Path.of(\"/ro-mount/gen\"));\n// after\nPath root = Files.createDirectories(Path.of(\"/home/ci/writable/gen\"));","handlingStrategy":"try-catch","validationCode":"Path target = projectRoot.resolve(packagePath + \"/graph\"); if (!Files.isDirectory(projectRoot) || !Files.isWritable(projectRoot)) { throw new IllegalStateException(\"Project root is not a writable directory: \" + projectRoot); }","typeGuard":"null","tryCatchPattern":"try { Path dir = ContributorFileUtil.createDirectory(projectRoot, packagePath); } catch (RuntimeException e) { log.error(\"Directory creation failed\", e.getCause()); }","preventionTips":["Check write permissions on the output root before generation","Sanitize package names used as path segments","Run generators as a user with access to the target directory","Monitor disk space in CI environments"],"tags":["java","filesystem","io","directory-creation"],"backgroundTag":"file-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}