SonarSource/sonarqube · error · IllegalStateException

Fail to open file

Error message

Fail to open file 

What it means

JavaSerializationCacheAppender's constructor opens the cache file to append objects, creating an ObjectOutputStream that deliberately skips the stream header (it was already written by the DiskCache constructor). Any IOException while opening the file is wrapped 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:96

      return new ObjectInputStreamIterator<>(FileUtils.openInputStream(file));
    } catch (IOException e) {
      throw new IllegalStateException("Fail to traverse file: " + file, e);
    }
  }

  public class JavaSerializationCacheAppender<O extends Serializable> implements CacheAppender<O> {
    private final ObjectOutputStream output;

    private JavaSerializationCacheAppender() {
      try {
        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

  1. Verify the cache file still exists and is writable when the task runs; stop external cleanup during task execution
  2. Check disk space and mount state on the CE node
  3. Rerun the task to rebuild the cache file
  4. Fix ownership/permissions of the CE workspace directory
Defensive patterns

Strategy: validation

Validate before calling

if (!file.isFile() || !file.canWrite()) {
  throw new IllegalStateException("Cannot append to cache file: " + file);
}

Try / catch

try {
  CacheAppender<O> appender = cache.newAppender();
} catch (IllegalStateException e) {
  LOGGER.error("Failed to open cache appender for {}", file, e.getCause());
  throw e;
}

Prevention

When it happens

Trigger: newAppender() invoked when the file cannot be opened for append — file deleted after cache construction, permissions changed, or disk became full/unavailable between construction and appender creation.

Common situations: Long report processing where cleanup or quota eviction removes the cache file mid-task; read-only remount of the workspace volume; race with another process locking/truncating the file.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/8675f2e79f8996f4. Report an issue: GitHub.