{"record":{"id":"84d65a9ed6243461","repo":"SonarSource/sonarqube","slug":"fail-to-write-into-file-84d65a","errorCode":null,"errorMessage":"Fail to write into file ","messagePattern":"Fail to write into file ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/JavaSerializationDiskCache.java","lineNumber":107,"sourceCode":"        this.output = new ObjectOutputStream(new FileOutputStream(file, true)) {\n          @Override\n          protected void writeStreamHeader() {\n            // do not write stream headers as it's already done in constructor of DiskCache\n          }\n        };\n      } catch (IOException e) {\n        throw new IllegalStateException(\"Fail to open file \" + file, e);\n      }\n    }\n\n    @Override\n    public CacheAppender append(O object) {\n      try {\n        output.writeObject(object);\n        output.reset();\n        return this;\n      } catch (IOException e) {\n        throw new IllegalStateException(\"Fail to write into file \" + file, e);\n      }\n    }\n\n    @Override\n    public void close() {\n      system2.close(output);\n    }\n  }\n}\n","sourceCodeStart":89,"sourceCodeEnd":117,"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#L89-L117","documentation":"JavaSerializationCacheAppender.append serializes an object into the open ObjectOutputStream and resets the stream for the next object. If writeObject throws IOException (stream closed, disk full, underlying file gone), it throws an IllegalStateException with the file path.","triggerScenarios":"append(object) called after the appender/output stream was closed, or mid-write when the disk fills up or the file descriptor becomes invalid (file deleted, NFS failure).","commonSituations":"Calling append after close() by mistake; disk quota exceeded during large analysis reports; stale file handles on network filesystems during long CE tasks.","solutions":["Ensure append() is not called after close() on the appender; check the producing code's lifecycle","Free disk space / increase quota on the CE node","Check filesystem health (stale NFS handles, deleted file) and rerun the task","Wrap the whole cache write phase so a single appender instance is used and closed exactly once"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (appenderClosed) {\n  throw new IllegalStateException(\"append() called after close()\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  appender.append(object);\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Failed to append to cache {}\", file, e.getCause());\n  IOUtils.closeQuietly(appender);\n  throw e;\n}","preventionTips":["Use try-with-resources or a strict single-owner lifecycle for the appender (append...close once)","Monitor disk usage; partial disk-full failures surface here","Never share one appender across threads without synchronization","Rerun the task after any mid-write filesystem failure to rebuild a consistent cache"],"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"}