{"record":{"id":"8675f2e79f8996f4","repo":"SonarSource/sonarqube","slug":"fail-to-open-file","errorCode":null,"errorMessage":"Fail to open file ","messagePattern":"Fail to open 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":96,"sourceCode":"      return new ObjectInputStreamIterator<>(FileUtils.openInputStream(file));\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Fail to traverse file: \" + file, e);\n    }\n  }\n\n  public class JavaSerializationCacheAppender<O extends Serializable> implements CacheAppender<O> {\n    private final ObjectOutputStream output;\n\n    private JavaSerializationCacheAppender() {\n      try {\n        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    }","sourceCodeStart":78,"sourceCodeEnd":114,"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#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the cache file still exists and is writable when the task runs; stop external cleanup during task execution","Check disk space and mount state on the CE node","Rerun the task to rebuild the cache file","Fix ownership/permissions of the CE workspace directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!file.isFile() || !file.canWrite()) {\n  throw new IllegalStateException(\"Cannot append to cache file: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try {\n  CacheAppender<O> appender = cache.newAppender();\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Failed to open cache appender for {}\", file, e.getCause());\n  throw e;\n}","preventionTips":["Keep the cache file alive for the whole task duration; avoid mid-task eviction","Check disk space before large analysis reports","Avoid concurrent processes locking or truncating the same cache file","Use stable local storage for the CE workspace"],"tags":["io","serialization","disk-cache","file-open","sonarqube"],"backgroundTag":"file-open-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"}