{"record":{"id":"944f1a5943f2d59e","repo":"SonarSource/sonarqube","slug":"fail-to-traverse-file","errorCode":null,"errorMessage":"Fail to traverse file: ","messagePattern":"Fail to traverse 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":80,"sourceCode":"    }\n  }\n\n  @Override\n  public long fileSize() {\n    return file.length();\n  }\n\n  @Override\n  public CacheAppender<O> newAppender() {\n    return new JavaSerializationCacheAppender();\n  }\n\n  @Override\n  public CloseableIterator<O> traverse() {\n    try {\n      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    }","sourceCodeStart":62,"sourceCodeEnd":98,"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#L62-L98","documentation":"traverse() opens the previously written serialization cache file and returns a CloseableIterator over its objects. If the file cannot be opened for reading (IOException), e.g. it was deleted between write and read, it throws an IllegalStateException wrapping the cause.","triggerScenarios":"traverse() called after the cache file was produced but FileUtils.openInputStream(file) fails — file removed by cleanup, workspace wiped between steps, or wrong file path/state.","commonSituations":"Concurrent CE workers or cleanup jobs deleting workspace cache files; NFS/network share with stale handles; cache file never fully written because an earlier step crashed.","solutions":["Ensure no external process (tmp cleaner, other worker) deletes files under the CE workspace while a task runs","Check that the cache file exists at the reported path and inspect filesystem health (NFS stale mounts)","Rerun the analysis task so the cache is rebuilt from scratch","Fix permissions so the sonarqube user can read its own workspace files"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!file.isFile()) {\n  throw new IllegalStateException(\"Cache file missing before traversal: \" + file);\n}\nif (!file.canRead()) {\n  throw new IllegalStateException(\"Cache file not readable: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try (CloseableIterator<O> it = cache.traverse()) {\n  // consume\n} catch (IllegalStateException e) {\n  LOGGER.error(\"Cache traversal failed for {}\", file, e.getCause());\n  // rebuild cache by rerunning the producing step/task\n  throw e;\n}","preventionTips":["Prevent external cleanup jobs from touching the CE workspace during task execution","Use local disk rather than flaky network mounts for cache files","Verify the cache-producing step completed before traversing","Alert on workspace files deleted mid-task"],"tags":["io","serialization","disk-cache","file-read","sonarqube"],"backgroundTag":"file-read-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"}