{"record":{"id":"1c2570611d79e9f6","repo":"airbnb/lottie-android","slug":"lottieanimator-does-not-support-setduration","errorCode":null,"errorMessage":"LottieAnimator does not support setDuration.","messagePattern":"LottieAnimator does not support setDuration\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lottie/src/main/java/com/airbnb/lottie/utils/BaseLottieAnimator.java","lineNumber":26,"sourceCode":"import java.util.Set;\nimport java.util.concurrent.CopyOnWriteArraySet;\n\npublic abstract class BaseLottieAnimator extends ValueAnimator {\n  private final Set<ValueAnimator.AnimatorUpdateListener> updateListeners = new CopyOnWriteArraySet<>();\n  private final Set<AnimatorListener> listeners = new CopyOnWriteArraySet<>();\n  private final Set<Animator.AnimatorPauseListener> pauseListeners = new CopyOnWriteArraySet<>();\n\n\n  @Override public long getStartDelay() {\n    throw new UnsupportedOperationException(\"LottieAnimator does not support getStartDelay.\");\n  }\n\n  @Override public void setStartDelay(long startDelay) {\n    throw new UnsupportedOperationException(\"LottieAnimator does not support setStartDelay.\");\n  }\n\n  @Override public ValueAnimator setDuration(long duration) {\n    throw new UnsupportedOperationException(\"LottieAnimator does not support setDuration.\");\n  }\n\n  @Override public void setInterpolator(TimeInterpolator value) {\n    throw new UnsupportedOperationException(\"LottieAnimator does not support setInterpolator.\");\n  }\n\n  public void addUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {\n    updateListeners.add(listener);\n  }\n\n  public void removeUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {\n    updateListeners.remove(listener);\n  }\n\n  public void removeAllUpdateListeners() {\n    updateListeners.clear();\n  }\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/airbnb/lottie-android/blob/05ea92e90381eb8a8ae06855ea2b74f322bebbec/lottie/src/main/java/com/airbnb/lottie/utils/BaseLottieAnimator.java#L8-L44","documentation":"BaseLottieAnimator overrides ValueAnimator.setDuration(long) to unconditionally throw UnsupportedOperationException. Lottie animation duration is determined entirely by the composition's frame range (endFrame - startFrame) divided by the frame rate — it cannot be set externally. The override ensures callers cannot accidentally override the composition-derived duration.","triggerScenarios":"Calling setDuration(ms) on a LottieValueAnimator, or on LottieAnimationView if it delegates to its internal animator. Also triggered by Android framework code or libraries that set duration generically on all ValueAnimators. The throw is at BaseLottieAnimator.java:26.","commonSituations":"A developer expects to control playback duration like a standard ValueAnimator. Code migrated from ObjectAnimator usage. Animation libraries that set duration on all animators. Using builder patterns or DSLs that chain .setDuration(). IDE auto-complete suggesting setDuration().","solutions":["To control the effective playback range, use LottieAnimationView.setMinProgress()/setMaxProgress() or LottieValueAnimator.setMinFrame()/setMaxFrame() to limit which frames are played","To change playback speed, use LottieAnimationView.setSpeed() or animator.setSpeed() — this effectively changes duration without setting it directly","Remove any setDuration() calls on LottieAnimator instances from your code"],"exampleFix":"// before: animator.setDuration(2000);\n// after:  // control effective duration via speed or frame range\n//         // duration = frameRange / frameRate, so:\n//         // to make it ~2s, adjust speed accordingly\n//         float currentDuration = (maxFrame - minFrame) / frameRate * 1000f;\n//         float speed = currentDuration / 2000f;\n//         lottieAnimationView.setSpeed(speed);\n//         lottieAnimationView.playAnimation();","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Guard against calling setDuration on LottieAnimator\nboolean isLottieAnimator(ValueAnimator animator) {\n  return animator instanceof com.airbnb.lottie.utils.BaseLottieAnimator;\n}\n\n// Safe access:\nvoid safeSetDuration(ValueAnimator animator, long duration) {\n  if (animator instanceof com.airbnb.lottie.utils.BaseLottieAnimator) {\n    throw new IllegalArgumentException(\"Use setSpeed or setMinAndMaxFrame for LottieAnimator\");\n  }\n  animator.setDuration(duration);\n}","tryCatchPattern":null,"preventionTips":["Never call setDuration() on a LottieValueAnimator","Control effective duration via setSpeed() or setMinAndMaxFrame()","Type-check for BaseLottieAnimator in generic animation configuration code"],"tags":["lottie","animation","unsupported-operation","android"],"backgroundTag":null,"analyzedSha":"05ea92e90381eb8a8ae06855ea2b74f322bebbec","analyzedAt":"2026-08-14T00:51:35.636Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}