SonarSource/sonarqube · error · IllegalStateException
Fail to write into file
Error message
Fail to write into file
What it means
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.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/JavaSerializationDiskCache.java:107
this.output = new ObjectOutputStream(new FileOutputStream(file, true)) {
@Override
protected void writeStreamHeader() {
// do not write stream headers as it's already done in constructor of DiskCache
}
};
} catch (IOException e) {
throw new IllegalStateException("Fail to open file " + file, e);
}
}
@Override
public CacheAppender append(O object) {
try {
output.writeObject(object);
output.reset();
return this;
} catch (IOException e) {
throw new IllegalStateException("Fail to write into file " + file, e);
}
}
@Override
public void close() {
system2.close(output);
}
}
}
View on GitHub (pinned to 184c821202)
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
Defensive patterns
Strategy: try-catch
Validate before calling
if (appenderClosed) {
throw new IllegalStateException("append() called after close()");
} Try / catch
try {
appender.append(object);
} catch (IllegalStateException e) {
LOGGER.error("Failed to append to cache {}", file, e.getCause());
IOUtils.closeQuietly(appender);
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: Calling append after close() by mistake; disk quota exceeded during large analysis reports; stale file handles on network filesystems during long CE tasks.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Fail to write into file:
- Fail to traverse file:
- Fail to open file
- Ad-hoc rules export failed after processing %d rules success
- Can not write to file
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/84d65a9ed6243461.
Report an issue: GitHub.