{"record":{"id":"95c44f813fc08a0b","repo":"airbnb/lottie-android","slug":"cache-file-must-be-a-directory","errorCode":null,"errorMessage":"cache file must be a directory","messagePattern":"cache file must be a directory","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lottie/src/main/java/com/airbnb/lottie/LottieConfig.java","lineNumber":75,"sourceCode":"    public Builder setNetworkFetcher(@NonNull LottieNetworkFetcher fetcher) {\n      this.networkFetcher = fetcher;\n      return this;\n    }\n\n    /**\n     * Provide your own network cache directory. By default, animations will be saved in your application's cacheDir/lottie_network_cache.\n     *\n     * @see #setNetworkCacheProvider(LottieNetworkCacheProvider)\n     */\n    @NonNull\n    public Builder setNetworkCacheDir(@NonNull final File file) {\n      if (cacheProvider != null) {\n        throw new IllegalStateException(\"There is already a cache provider!\");\n      }\n      cacheProvider = new LottieNetworkCacheProvider() {\n        @Override @NonNull public File getCacheDir() {\n          if (!file.isDirectory()) {\n            throw new IllegalArgumentException(\"cache file must be a directory\");\n          }\n          return file;\n        }\n      };\n      return this;\n    }\n\n    /**\n     * Provide your own network cache provider. By default, animations will be saved in your application's cacheDir/lottie_network_cache.\n     */\n    @NonNull\n    public Builder setNetworkCacheProvider(@NonNull final LottieNetworkCacheProvider fileCacheProvider) {\n      if (cacheProvider != null) {\n        throw new IllegalStateException(\"There is already a cache provider!\");\n      }\n      cacheProvider = new LottieNetworkCacheProvider() {\n        @NonNull @Override public File getCacheDir() {\n          File file = fileCacheProvider.getCacheDir();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/airbnb/lottie-android/blob/05ea92e90381eb8a8ae06855ea2b74f322bebbec/lottie/src/main/java/com/airbnb/lottie/LottieConfig.java#L57-L93","documentation":"Thrown by the LottieNetworkCacheProvider created inside setNetworkCacheDir when getCacheDir() is invoked and File#isDirectory() returns false for the supplied file. This means the path either does not exist or exists as a regular file rather than a directory.","triggerScenarios":"Passing a File to setNetworkCacheDir that points to a non-existent path or to an existing regular file; the directory not yet created on disk when the network cache first tries to write; a path collision where a file (not a folder) was already written at that location.","commonSituations":"Forgetting to call mkdirs() on a custom cache directory; pointing at context.getCacheDir() then appending a filename instead of a folder name; a previous run wrote a file at the intended directory path.","solutions":["Before setNetworkCacheDir, create the directory: File dir = new File(getCacheDir(), \"lottie_network_cache\"); dir.mkdirs();","Verify the File refers to a folder, not a file name - append a sub-folder segment, not a filename.","If the path is occupied by a regular file, delete it or choose a different directory.","Call setNetworkCacheProvider instead and create the directory lazily inside the provider."],"exampleFix":"// before\nFile cache = new File(context.getCacheDir(), \"lottie_network_cache.dat\");\nLottieConfig.Builder().setNetworkCacheDir(cache); // .dat is a file\n\n// after\nFile cache = new File(context.getCacheDir(), \"lottie_network_cache\");\ncache.mkdirs();\nLottieConfig.Builder().setNetworkCacheDir(cache);","handlingStrategy":"validation","validationCode":"File dir = new File(getCacheDir(), \"lottie_network_cache\");\nif (!dir.exists() && !dir.mkdirs()) throw new IOException(\"cannot create cache dir\");\nif (!dir.isDirectory()) throw new IllegalStateException(dir + \" is not a directory\");\nbuilder.setNetworkCacheDir(dir);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always mkdirs() on a custom cache directory before registering it.","Pass a folder path, never a filename.","Assert dir.isDirectory() right before setNetworkCacheDir during development."],"tags":["cache","filesystem","network","configuration"],"backgroundTag":null,"analyzedSha":"05ea92e90381eb8a8ae06855ea2b74f322bebbec","analyzedAt":"2026-08-14T00:51:35.636Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}