{"record":{"id":"a2019a8699edd49b","repo":"material-components/material-components-android","slug":"cannot-set-showanimator-while-the-current-showanim","errorCode":null,"errorMessage":"Cannot set showAnimator while the current showAnimator is running.","messagePattern":"Cannot set showAnimator while the current showAnimator is running\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java","lineNumber":367,"sourceCode":"  public void setColorFilter(@Nullable ColorFilter colorFilter) {\n    paint.setColorFilter(colorFilter);\n    invalidateSelf();\n  }\n\n  @Override\n  public int getOpacity() {\n    return PixelFormat.TRANSLUCENT;\n  }\n\n  /**\n   * Sets a value animator for show animation. This only takes effect when the drawable is not\n   * currently being shown.\n   *\n   * @param showAnimator A ValueAnimator used for show animation.\n   */\n  private void setShowAnimator(@NonNull ValueAnimator showAnimator) {\n    if (this.showAnimator != null && this.showAnimator.isRunning()) {\n      throw new IllegalArgumentException(\n          \"Cannot set showAnimator while the current showAnimator is running.\");\n    }\n    this.showAnimator = showAnimator;\n\n    // Adds a listener to dispatch animation callbacks at the end.\n    showAnimator.addListener(\n        new AnimatorListenerAdapter() {\n          @Override\n          public void onAnimationStart(Animator animation) {\n            super.onAnimationStart(animation);\n\n            dispatchAnimationStart();\n          }\n        });\n  }\n\n  @NonNull\n  ValueAnimator getHideAnimator() {","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java#L349-L385","documentation":"DrawableWithAnimatedVisibilityChange.setShowAnimator throws IllegalArgumentException if a replacement show animator is set while the current show animator is still running. Swapping an in-flight animator would orphan listeners and animation state, so the setter refuses until the running animation ends.","triggerScenarios":"Calling a method that replaces the show animator (e.g. mutating showAnimator on the drawable/indicator while it is mid show-animation); typically via custom animation injection right after show() was called.","commonSituations":"Customizing show/hide animators on a progress indicator drawable in response to config changes while the indicator is animating in; rapid successive API calls before the previous animation finished.","solutions":["Wait for the current show animation to end (listen for animation end) before replacing the animator","Cancel the running animator first, then set the new one","Set custom animators once during setup, before any show/hide animation can run"],"exampleFix":"// before\nindicator.show()\nindicator.getIndeterminateDrawable().setShowAnimator(newAnimator) // throws while running\n// after\nindicator.hide()\nindicator.getIndeterminateDrawable().setShowAnimator(newAnimator)\nindicator.show()","handlingStrategy":"validation","validationCode":"fun replaceShowAnimator(drawable: DrawableWithAnimatedVisibilityChange, animator: ValueAnimator) {\n    drawable.hideNow() // ensure not mid-show\n    drawable.setShowAnimator(animator)\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.w(TAG, \"Show animator running; deferring swap to animation end\", e); deferSwapUntilAnimationEnd() }","preventionTips":["Install custom show/hide animators once during initialization","Never swap animators while animations are running","Listen for animation end before replacing animators"],"tags":["android","material-components","progressindicator","animation","animator","state"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}