{"record":{"id":"7bcf59de6d7d19d1","repo":"airbnb/lottie-android","slug":"there-is-already-a-cache-provider","errorCode":null,"errorMessage":"There is already a cache provider!","messagePattern":"There is already a cache provider!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lottie/src/main/java/com/airbnb/lottie/LottieConfig.java","lineNumber":70,"sourceCode":"    /**\n     * Lottie has a default network fetching stack built on {@link java.net.HttpURLConnection}. However, if you would like to hook into your own\n     * network stack for performance, caching, or analytics, you may replace the internal stack with your own.\n     */\n    @NonNull\n    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) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/airbnb/lottie-android/blob/05ea92e90381eb8a8ae06855ea2b74f322bebbec/lottie/src/main/java/com/airbnb/lottie/LottieConfig.java#L52-L88","documentation":"Thrown by LottieConfig.Builder#setNetworkCacheDir when a cache provider has already been registered on the same Builder instance. The cacheProvider field is single-slot, so configuring a cache directory twice (or after setNetworkCacheProvider) is treated as a programming error.","triggerScenarios":"Calling setNetworkCacheDir(file) a second time on one LottieConfig.Builder, or calling setNetworkCacheDir after setNetworkCacheProvider on the same Builder.","commonSituations":"Building LottieConfig in a loop or a helper that always calls setNetworkCacheDir and is invoked twice; reusing a Builder reference; migrating from setNetworkCacheDir to setNetworkCacheProvider and leaving the old call in place.","solutions":["Ensure setNetworkCacheDir is called at most once per LottieConfig.Builder instance.","If you need both behaviors, pick exactly one of setNetworkCacheDir or setNetworkCacheProvider per Builder.","Build the LottieConfig in a single, idempotent initialization method (e.g. guarded by a static 'initialized' flag or a DI provider)."],"exampleFix":"// before - helper called twice\nconfigureLottie(builder);\nbuilder.setNetworkCacheDir(getCacheDir()); // throws: provider already set\n\n// after - single ownership of cache configuration\npublic LottieConfig buildLottieConfig() {\n  LottieConfig.Builder b = new LottieConfig.Builder();\n  b.setNetworkCacheDir(getCacheDir());\n  return b.build();\n}","handlingStrategy":"validation","validationCode":"// Guard cache configuration with a flag\nprivate volatile boolean lottieCacheConfigured;\npublic synchronized void ensureLottieConfig(File cacheDir) {\n  if (lottieCacheConfigured) return;\n  LottieConfig cfg = new LottieConfig.Builder()\n      .setNetworkCacheDir(cacheDir)\n      .build();\n  Lottie.initialize(cfg);\n  lottieCacheConfigured = true;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call Lottie.initialize exactly once from Application.onCreate.","Centralize cache setup in a single guarded method.","Never call both setNetworkCacheDir and setNetworkCacheProvider on one Builder."],"tags":["configuration","cache","network","builder"],"backgroundTag":null,"analyzedSha":"05ea92e90381eb8a8ae06855ea2b74f322bebbec","analyzedAt":"2026-08-14T00:51:35.636Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}