{"record":{"id":"69fe3bb912791d84","repo":"elastic/elasticsearch","slug":"could-not-create-directory-packagedir","errorCode":null,"errorMessage":"Could not create directory: {packageDir}","messagePattern":"Could not create directory: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/esql/GenerateEsqlSpecTestsTask.java","lineNumber":93,"sourceCode":"    @Input\n    public abstract ListProperty<String> getVariantSpecFilePatterns();\n\n    @OutputDirectory\n    public abstract DirectoryProperty getOutputDirectory();\n\n    @Inject\n    public abstract FileSystemOperations getFileSystemOperations();\n\n    @TaskAction\n    public void generate() throws IOException {\n        File outputDir = getOutputDirectory().getAsFile().get();\n        getFileSystemOperations().delete(spec -> spec.delete(outputDir));\n\n        String packageName = getPackageName().get();\n        String packagePath = packageName.replace('.', '/');\n        File packageDir = new File(outputDir, packagePath);\n        if (packageDir.mkdirs() == false && packageDir.exists() == false) {\n            throw new IOException(\"Could not create directory: \" + packageDir);\n        }\n\n        List<String> prefixes = getVariantPrefixes().get();\n        List<String> baseClasses = getVariantBaseClasses().get();\n        List<String> allEncodedPatterns = getVariantSpecFilePatterns().get();\n        if (prefixes.size() != baseClasses.size() || prefixes.size() != allEncodedPatterns.size()) {\n            throw new IllegalStateException(\"variantPrefixes, variantBaseClasses, and variantSpecFilePatterns must have the same length\");\n        }\n\n        File specDir = getSpecFilesDir().getAsFile().get();\n        File[] specFiles = specDir.listFiles((dir, name) -> name.endsWith(\".csv-spec\"));\n        if (specFiles == null) {\n            return;\n        }\n        Arrays.sort(specFiles);\n        for (File specFile : specFiles) {\n            String specFileName = specFile.getName();\n            String baseName = specFileName.substring(0, specFileName.length() - \".csv-spec\".length());","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/esql/GenerateEsqlSpecTestsTask.java#L75-L111","documentation":"Thrown by GenerateEsqlSpecTestsTask.generate() when the package directory for generated ES|QL spec test source files cannot be created. The task deletes the output directory, then derives a package path from the configured package name (converting dots to slashes) and calls mkdirs(). If mkdirs() returns false AND the directory does not exist afterward, it throws IOException.","triggerScenarios":"The output directory is deleted via FileSystemOperations.delete, then packageDir.mkdirs() is called. mkdirs() returns false if a parent path component is a regular file, if permissions are insufficient, or if the path is read-only. The check `mkdirs() == false && exists() == false` handles the race where mkdirs returns false because the directory already existed (created by a concurrent process), but a genuine failure propagates.","commonSituations":"The output directory path conflicts with a file of the same name left by a previous incomplete build. The build runs on a read-only filesystem or a CI agent with restricted write access. The package name property is misconfigured, producing a path that resolves outside the project build directory.","solutions":["Run ./gradlew clean to remove stale output directories that may conflict with file-typed path components.","Verify the packageName property resolves to a valid path: ensure it contains no path separators or invalid characters.","Ensure the Gradle daemon has write permissions to the output directory location.","Check that getOutputDirectory() is set to a writable location within the project's build directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate output directory writability\nFile outputDir = getOutputDirectory().getAsFile().get();\nFile parent = outputDir.getParentFile();\nif (parent != null && parent.exists() && !parent.canWrite()) {\n    throw new GradleException(\"Cannot write to output directory: \" + outputDir);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run ./gradlew clean to remove stale files that may conflict with directory creation.","Keep generated output within the build directory.","Verify the package name property contains only valid Java identifier characters."],"tags":["esql","code-generation","filesystem","build-task","io"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}