{"record":{"id":"a3a245f43e39a4ee","repo":"material-components/material-components-android","slug":"is-not-a-valid-tabindicatoranimationmode","errorCode":null,"errorMessage":" is not a valid TabIndicatorAnimationMode","messagePattern":" is not a valid TabIndicatorAnimationMode","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/tabs/TabLayout.java","lineNumber":1233,"sourceCode":"   *     #INDICATOR_ANIMATION_MODE_ELASTIC}\n   * @attr ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode\n   * @see #getTabIndicatorAnimationMode()\n   */\n  public void setTabIndicatorAnimationMode(\n      @TabIndicatorAnimationMode int tabIndicatorAnimationMode) {\n    this.tabIndicatorAnimationMode = tabIndicatorAnimationMode;\n    switch (tabIndicatorAnimationMode) {\n      case INDICATOR_ANIMATION_MODE_LINEAR:\n        this.tabIndicatorInterpolator = new TabIndicatorInterpolator();\n        break;\n      case INDICATOR_ANIMATION_MODE_ELASTIC:\n        this.tabIndicatorInterpolator = new ElasticTabIndicatorInterpolator();\n        break;\n      case INDICATOR_ANIMATION_MODE_FADE:\n        this.tabIndicatorInterpolator = new FadeTabIndicatorInterpolator();\n        break;\n      default:\n        throw new IllegalArgumentException(\n            tabIndicatorAnimationMode + \" is not a valid TabIndicatorAnimationMode\");\n    }\n  }\n\n  /**\n   * Get the current indicator animation mode used to animate the selection indicator between\n   * destinations.\n   *\n   * @return one of {@link #INDICATOR_ANIMATION_MODE_LINEAR} or {@link\n   *     #INDICATOR_ANIMATION_MODE_ELASTIC}\n   * @attr ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode\n   * @see #setTabIndicatorAnimationMode(int)\n   */\n  @TabIndicatorAnimationMode\n  public int getTabIndicatorAnimationMode() {\n    return tabIndicatorAnimationMode;\n  }\n","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/tabs/TabLayout.java#L1215-L1251","documentation":"setTabIndicatorAnimationMode(int) maps the mode to an interpolator via a switch over the @TabIndicatorAnimationMode IntDef constants (LINEAR, ELASTIC, FADE). Any value outside those constants falls to default and throws IllegalArgumentException, because no interpolator exists for it.","triggerScenarios":"Passing a raw int that is not one of TabLayout.INDICATOR_ANIMATION_MODE_LINEAR/ELASTIC/FADE (e.g. a typo'd constant or a value read from an unvalidated source), or setting an invalid app:tabIndicatorAnimationMode in XML.","commonSituations":"Storing the mode as an int in preferences/payloads and passing it back unchecked; using a constant copied from an older/newer version that does not exist in the linked library version.","solutions":["Use only the declared constants: TabLayout.INDICATOR_ANIMATION_MODE_LINEAR, INDICATOR_ANIMATION_MODE_ELASTIC, INDICATOR_ANIMATION_MODE_FADE.","Validate persisted/int-derived values against the constant set before calling the setter.","Check XML app:tabIndicatorAnimationMode values against the supported set (linear, elastic, fade)."],"exampleFix":"// before\ntabLayout.setTabIndicatorAnimationMode(modeFromServer); // e.g. 7\n\n// after\nint mode = (modeFromServer == INDICATOR_ANIMATION_MODE_ELASTIC)\n    ? INDICATOR_ANIMATION_MODE_ELASTIC : INDICATOR_ANIMATION_MODE_LINEAR;\ntabLayout.setTabIndicatorAnimationMode(mode);","handlingStrategy":"validation","validationCode":"private static final Set<Integer> VALID_MODES = Set.of(\n    TabLayout.INDICATOR_ANIMATION_MODE_LINEAR,\n    TabLayout.INDICATOR_ANIMATION_MODE_ELASTIC,\n    TabLayout.INDICATOR_ANIMATION_MODE_FADE);\n\nprivate void applyMode(int mode) {\n  if (VALID_MODES.contains(mode)) tabLayout.setTabIndicatorAnimationMode(mode);\n}","typeGuard":"private boolean isValidIndicatorAnimationMode(int mode) {\n  return mode == TabLayout.INDICATOR_ANIMATION_MODE_LINEAR\n      || mode == TabLayout.INDICATOR_ANIMATION_MODE_ELASTIC\n      || mode == TabLayout.INDICATOR_ANIMATION_MODE_FADE;\n}","tryCatchPattern":null,"preventionTips":["Only pass IntDef constants, never raw ints.","Annotate your own wrappers with @TabIndicatorAnimationMode so the IDE enforces the set.","Validate persisted values before use."],"tags":["tablayout","validation","android","ui"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}