{"record":{"id":"1cc5539ea75c518a","repo":"GoogleContainerTools/jib","slug":"no-or-multiple-layer-files-found-for-layer-hash-d","errorCode":null,"errorMessage":"No or multiple layer files found for layer hash <diffId> in directory: <layerDirectory>","messagePattern":"No or multiple layer files found for layer hash <diffId> in directory: <layerDirectory>","errorType":"exception","errorClass":"CacheCorruptedException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java","lineNumber":198,"sourceCode":"   * Retrieves the {@link CachedLayer} for the local base image layer with the given diff ID.\n   *\n   * @param diffId the diff ID\n   * @return the {@link CachedLayer} referenced by the diff ID, if found\n   * @throws CacheCorruptedException if the cache was found to be corrupted\n   * @throws IOException if an I/O exception occurs\n   */\n  Optional<CachedLayer> retrieveTarLayer(DescriptorDigest diffId)\n      throws IOException, CacheCorruptedException {\n    Path layerDirectory = cacheStorageFiles.getLocalDirectory().resolve(diffId.getHash());\n    if (!Files.exists(layerDirectory)) {\n      return Optional.empty();\n    }\n\n    try (Stream<Path> files = Files.list(layerDirectory)) {\n      List<Path> layerFiles =\n          files.filter(CacheStorageFiles::isLayerFile).collect(Collectors.toList());\n      if (layerFiles.size() != 1) {\n        throw new CacheCorruptedException(\n            cacheStorageFiles.getCacheDirectory(),\n            \"No or multiple layer files found for layer hash \"\n                + diffId.getHash()\n                + \" in directory: \"\n                + layerDirectory);\n      }\n\n      Path layerFile = layerFiles.get(0);\n      return Optional.of(\n          CachedLayer.builder()\n              .setLayerDigest(cacheStorageFiles.getDigestFromFilename(layerFile))\n              .setLayerSize(Files.size(layerFile))\n              .setLayerBlob(Blobs.from(layerFile))\n              .setLayerDiffId(diffId)\n              .build());\n    }\n  }\n","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java#L180-L216","documentation":"retrieveTarLayer(diffId) mirrors retrieve() but looks up a layer by its diff ID for tar-based (e.g. jib:buildTar / Docker daemon) flows. It expects exactly one layer file in the diff ID directory; any other count raises CacheCorruptedException with the diffId hash and directory in the message.","triggerScenarios":"retrieveTarLayer() is called and the layer directory keyed by diffId contains zero or multiple files recognized as layer files by CacheStorageFiles::isLayerFile.","commonSituations":"Interruption during tar layer extraction/writing, external tools modifying the cache, cache shared across Jib versions with different file naming so extra/missing files appear.","solutions":["Clear the cache directory and rebuild the tar image","Ensure only one Jib build runs per cache directory at a time","Check the layer directory for stray files and remove them if you know the correct one","Upgrade Jib to the latest patch version"],"exampleFix":"// before\nmvn jib:buildTar // fails: No or multiple layer files for sha256:diffid\n// after\nrm -rf ~/.cache/google-cloud-tools-java/jib && mvn jib:buildTar","handlingStrategy":"try-catch","validationCode":"long n = Files.list(diffIdDir).filter(Files::isRegularFile).count();\nif (n != 1) deleteRecursively(diffIdDir);","typeGuard":null,"tryCatchPattern":"try {\n  jibBuildTar();\n} catch (CacheCorruptedException e) {\n  wipeCache();\n  jibBuildTar();\n}","preventionTips":["Let builds finish before shutting down CI agents","Use a dedicated cache per job in CI","Avoid sharing cache volumes between Jib versions"],"tags":["cache","tar","corruption"],"backgroundTag":"corrupted-cache-metadata","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}