{"record":{"id":"ef7ebd7ac0d3609a","repo":"SonarSource/sonarqube","slug":"fail-to-write-into-file","errorCode":null,"errorMessage":"Fail to write into file: ","messagePattern":"Fail to write into file: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/JavaSerializationDiskCache.java","lineNumber":53,"sourceCode":" */\npublic final class JavaSerializationDiskCache<O extends Serializable> implements DiskCache<O> {\n\n  private final File file;\n  private final System2 system2;\n\n  public JavaSerializationDiskCache(File file, System2 system2) {\n    this.system2 = system2;\n    this.file = file;\n    OutputStream output = null;\n    boolean threw = true;\n    try {\n      // writes the serialization stream header required when calling \"traverse()\"\n      // on empty stream. Moreover it allows to call multiple times \"newAppender()\"\n      output = new ObjectOutputStream(new FileOutputStream(file));\n      output.flush();\n      threw = false;\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Fail to write into file: \" + file, e);\n    } finally {\n      if (threw) {\n        // do not hide initial exception\n        IOUtils.closeQuietly(output);\n      } else {\n        // raise an exception if can't close\n        system2.close(output);\n      }\n    }\n  }\n\n  @Override\n  public long fileSize() {\n    return file.length();\n  }\n\n  @Override\n  public CacheAppender<O> newAppender() {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/JavaSerializationDiskCache.java#L35-L71","documentation":"JavaSerializationDiskCache's constructor opens the cache file and writes the serialization stream header needed for later traversal and appending. If opening/writing the file throws IOException (missing directory, permissions, disk full), it wraps it in an IllegalStateException with the file path.","triggerScenarios":"new JavaSerializationDiskCache(...) during CE report processing when new FileOutputStream(file) or the first ObjectOutputStream header write fails — nonexistent parent directory, read-only filesystem, no write permission, or disk full.","commonSituations":"CE workspace directory deleted or not writable by the sonarqube user; disk quota/full volume on the compute engine node; container with read-only tmp mount.","solutions":["Verify the CE working directory (sonar.path.data / workspace) exists and is writable by the sonarqube process user","Free disk space / fix quota on the node","Fix filesystem permissions or mount (e.g. chmod/chown, remount rw)","Restart the CE worker after fixing the filesystem so it recreates the cache file"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File parent = file.getParentFile();\nif (parent == null || !parent.isDirectory() || !parent.canWrite()) {\n  throw new IllegalStateException(\"Cache directory missing or not writable: \" + parent);\n}\nif (file.exists() && !file.canWrite()) {\n  throw new IllegalStateException(\"Cache file not writable: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n  JavaSerializationDiskCache<O> cache = new JavaSerializationDiskCache<>(file, system2);\n} catch (IllegalStateException e) {\n  // inspect cause: IOException with path; fix FS and retry once\n  LOGGER.error(\"Cannot create disk cache for {}\", file, e.getCause());\n  throw e;\n}","preventionTips":["Ensure the CE workspace directory exists and is writable by the sonarqube user before task start","Monitor free disk space and inodes on CE nodes","Avoid read-only mounts for the data/workspace paths","Pre-create and permission-check the cache directory in deployment scripts"],"tags":["io","serialization","disk-cache","file-write","sonarqube"],"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"}