{"record":{"id":"09f67a207ed93cb1","repo":"SonarSource/sonarqube","slug":"can-not-write-to-file","errorCode":null,"errorMessage":"Can not write to file ","messagePattern":"Can not write to file ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java","lineNumber":67,"sourceCode":"  public DumpWriterImpl(ProjectDescriptor descriptor, ProjectExportDumpFS projectExportDumpFS, TempFolder tempFolder) {\n    this.descriptor = descriptor;\n    this.projectExportDumpFS = projectExportDumpFS;\n    this.tempFolder = tempFolder;\n    this.rootDir = tempFolder.newDir();\n  }\n\n  @Override\n  public void write(ProjectDump.Metadata metadata) {\n    checkNotPublished();\n    if (metadataWritten.get()) {\n      throw new IllegalStateException(\"Metadata has already been written\");\n    }\n    File file = new File(rootDir, METADATA.filename());\n    try (FileOutputStream output = FILES2.openOutputStream(file, false)) {\n      PROTOBUF2.writeTo(metadata, output);\n      metadataWritten.set(true);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Can not write to file \" + file, e);\n    }\n  }\n\n  @Override\n  public <M extends Message> StreamWriter<M> newStreamWriter(DumpElement<M> elt) {\n    checkNotPublished();\n    File file = new File(rootDir, elt.filename());\n    return StreamWriterImpl.create(file);\n  }\n\n  @Override\n  public void publish() {\n    checkNotPublished();\n    if (!metadataWritten.get()) {\n      throw new IllegalStateException(\"Metadata is missing\");\n    }\n    File zip = tempFolder.newFile();\n    FILES2.zipDir(rootDir, zip);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/DumpWriterImpl.java#L49-L85","documentation":"When DumpWriterImpl writes ProjectDump.Metadata to the metadata file inside the dump root, an IOException while opening or writing the file is converted into an IllegalStateException with the message \"Can not write to file <path>\" plus the cause. The dump cannot proceed without metadata, so the export is aborted.","triggerScenarios":"Metadata file cannot be opened for writing (path doesn't exist, permission denied, disk full) or protobuf writeTo fails with an IOException during write(metadata).","commonSituations":"Insufficient disk space on the CE node; wrong ownership/permissions on the dump working directory; the rootDir was deleted or not created before the writer ran.","solutions":["Check the wrapped IOException cause for the exact filesystem reason","Free disk space on the volume holding the dump directory","Fix permissions/ownership of the dump working directory for the sonarqube/CE user","Ensure rootDir exists and is created before DumpWriterImpl is constructed"],"exampleFix":"// before\nFile file = new File(rootDir, METADATA.filename());\n// after: verify writability up-front\nFiles.createDirectories(rootDir.toPath());\nif (!rootDir.canWrite()) { throw new IllegalStateException(\"Dump dir not writable: \" + rootDir); }","handlingStrategy":"validation","validationCode":"Files.createDirectories(rootDir.toPath());\nif (!Files.isWritable(rootDir.toPath())) {\n  throw new IOException(\"Dump root not writable: \" + rootDir);\n}","typeGuard":null,"tryCatchPattern":"try { writer.write(metadata); } catch (IllegalStateException e) { logger.error(\"Cannot write metadata file: {}\", e.getCause() == null ? \"\" : e.getCause().getMessage(), e); }","preventionTips":["Check disk space before starting exports","Run the CE process with ownership of the dump working directory","Create and verify the dump root dir at pipeline start"],"tags":["sonarqube","project-export","io","filesystem"],"backgroundTag":"file-write-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}