{"record":{"id":"505bc88953765e01","repo":"GoogleContainerTools/jib","slug":"cachedirectorycreationexception-wrapping-ioexcepti","errorCode":null,"errorMessage":"CacheDirectoryCreationException wrapping IOException from cache directory creation","messagePattern":"CacheDirectoryCreationException wrapping IOException from cache directory creation","errorType":"exception","errorClass":"CacheDirectoryCreationException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/cache/Cache.java","lineNumber":59,"sourceCode":" *\n * <p>This class is immutable and safe to use across threads.\n */\n@Immutable\npublic class Cache {\n\n  /**\n   * Initializes the cache using {@code cacheDirectory} for storage.\n   *\n   * @param cacheDirectory the directory for the cache. Creates the directory if it does not exist.\n   * @return a new {@link Cache}\n   * @throws CacheDirectoryCreationException if an I/O exception occurs when creating cache\n   *     directory\n   */\n  public static Cache withDirectory(Path cacheDirectory) throws CacheDirectoryCreationException {\n    try {\n      Files.createDirectories(cacheDirectory);\n    } catch (IOException ex) {\n      throw new CacheDirectoryCreationException(ex);\n    }\n    return new Cache(new CacheStorageFiles(cacheDirectory));\n  }\n\n  private final CacheStorageWriter cacheStorageWriter;\n  private final CacheStorageReader cacheStorageReader;\n\n  private Cache(CacheStorageFiles cacheStorageFiles) {\n    cacheStorageWriter = new CacheStorageWriter(cacheStorageFiles);\n    cacheStorageReader = new CacheStorageReader(cacheStorageFiles);\n  }\n\n  /**\n   * Saves image metadata (a manifest list and a list of manifest/container configuration pairs) for\n   * an image reference.\n   *\n   * @param imageReference the image reference to save the metadata for\n   * @param metadata the image metadata","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/cache/Cache.java#L41-L77","documentation":"Cache.withDirectory creates the given cache directory before constructing the Cache. If Files.createDirectories throws an IOException (permissions, path is a file, disk issues), the IOException is wrapped in a CacheDirectoryCreationException so callers get a single, typed failure instead of a raw IOException.","triggerScenarios":"Calling Cache.withDirectory(path) when the path exists as a regular file, the process lacks write permission on the parent, the filesystem is read-only or full, or the path component is invalid/unwritable.","commonSituations":"Custom jib cache directory configured to an unwritable location in CI; a file accidentally occupying the cache path; read-only container filesystems; running under a service user without access to ~/.cache; NFS volumes with permission quirks.","solutions":["Check permissions on the cache directory path and its parent (the build user must be able to create/write it)","If the path exists as a file, remove it or pick a different cache directory","Set the jib cache directory explicitly to a writable location (jib.cacheDirectory Maven / --imageBuildCache Gradle or JibSystemProperties)","Ensure the filesystem is writable and has free space (read-only root fs: mount a writable volume for the cache)"],"exampleFix":"// before\nCache cache = Cache.withDirectory(Paths.get(\"/var/cache/jib\"));  // read-only dir\n// after\nCache cache = Cache.withDirectory(Paths.get(System.getProperty(\"java.io.tmpdir\"), \"jib-cache\"));","handlingStrategy":"validation","validationCode":"[ -e \"$CACHE_DIR\" ] && [ ! -d \"$CACHE_DIR\" ] && echo 'cache path is a file'; [ -d \"$CACHE_DIR\" ] && [ ! -w \"$CACHE_DIR\" ] && echo 'cache dir not writable'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the cache dir in CI setup with correct ownership"],"tags":["cache","filesystem","permissions","jib"],"backgroundTag":"mkdir-permission-denied","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"}