SonarSource/sonarqube · critical · IllegalStateException
Fail to write into file:
Error message
Fail to write into file:
What it means
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.
Source
Thrown at server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/util/cache/JavaSerializationDiskCache.java:53
*/
public final class JavaSerializationDiskCache<O extends Serializable> implements DiskCache<O> {
private final File file;
private final System2 system2;
public JavaSerializationDiskCache(File file, System2 system2) {
this.system2 = system2;
this.file = file;
OutputStream output = null;
boolean threw = true;
try {
// writes the serialization stream header required when calling "traverse()"
// on empty stream. Moreover it allows to call multiple times "newAppender()"
output = new ObjectOutputStream(new FileOutputStream(file));
output.flush();
threw = false;
} catch (IOException e) {
throw new IllegalStateException("Fail to write into file: " + file, e);
} finally {
if (threw) {
// do not hide initial exception
IOUtils.closeQuietly(output);
} else {
// raise an exception if can't close
system2.close(output);
}
}
}
@Override
public long fileSize() {
return file.length();
}
@Override
public CacheAppender<O> newAppender() {View on GitHub (pinned to 184c821202)
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
Defensive patterns
Strategy: try-catch
Validate before calling
File parent = file.getParentFile();
if (parent == null || !parent.isDirectory() || !parent.canWrite()) {
throw new IllegalStateException("Cache directory missing or not writable: " + parent);
}
if (file.exists() && !file.canWrite()) {
throw new IllegalStateException("Cache file not writable: " + file);
} Try / catch
try {
JavaSerializationDiskCache<O> cache = new JavaSerializationDiskCache<>(file, system2);
} catch (IllegalStateException e) {
// inspect cause: IOException with path; fix FS and retry once
LOGGER.error("Cannot create disk cache for {}", file, e.getCause());
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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/ef7ebd7ac0d3609a.
Report an issue: GitHub.