{"record":{"id":"29fd8ac7ac582003","repo":"material-components/material-components-android","slug":"a-materialspring-style-must-have-a-damping-value","errorCode":null,"errorMessage":"A MaterialSpring style must have a damping value.","messagePattern":"A MaterialSpring style must have a damping value\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/motion/MotionUtils.java","lineNumber":74,"sourceCode":"      @NonNull Context context, @AttrRes int attrResId, @StyleRes int defStyleRes) {\n\n    TypedValue tv = MaterialAttributes.resolve(context, attrResId);\n    TypedArray a;\n    if (tv == null) {\n      a = context.obtainStyledAttributes(null, R.styleable.MaterialSpring, 0, defStyleRes);\n    } else {\n      a = context.obtainStyledAttributes(tv.resourceId, R.styleable.MaterialSpring);\n    }\n\n    SpringForce springForce = new SpringForce();\n    try {\n      float stiffness = a.getFloat(R.styleable.MaterialSpring_stiffness, Float.MIN_VALUE);\n      if (stiffness == Float.MIN_VALUE) {\n        throw new IllegalArgumentException(\"A MaterialSpring style must have stiffness value.\");\n      }\n      float damping = a.getFloat(R.styleable.MaterialSpring_damping, Float.MIN_VALUE);\n      if (damping == Float.MIN_VALUE) {\n        throw new IllegalArgumentException(\"A MaterialSpring style must have a damping value.\");\n      }\n\n      springForce.setStiffness(stiffness);\n      springForce.setDampingRatio(damping);\n    } finally {\n      a.recycle();\n    }\n    return springForce;\n  }\n\n  /**\n   * Resolve a duration from a material duration theme attribute.\n   *\n   * @param context the context from where the theme attribute will be resolved.\n   * @param attrResId the {@code motionDuration*} theme attribute to resolve\n   * @param defaultDuration the duration to be returned if unable to resolve {@code attrResId}\n   * @return the resolved {@code int} duration which {@code attrResId} points to or the {@code\n   *     defaultDuration} if resolution was unsuccessful.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/motion/MotionUtils.java#L56-L92","documentation":"When resolving a MaterialSpring style into a SpringForce, MotionUtils requires a damping value in addition to stiffness. Float.MIN_VALUE is used as the sentinel default, and its presence means the style omitted MaterialSpring_damping, which throws IllegalArgumentException because SpringForce needs a damping ratio to behave predictably.","triggerScenarios":"resolveAsSpringForce resolves a style that defines stiffness but omits damping; e.g. a custom style overriding a motionEasing/spring theme attribute with only <item name=\"stiffness\">, or an incorrectly parented style missing the damping default.","commonSituations":"Copying a spring style from docs that only shows stiffness; upgrading Material library where damping defaults moved to a parent style the app no longer inherits; hand-writing the style in values/ without a correct parent.","solutions":["Add <item name=\"damping\">[value between 0 and 1+]</item> to the spring style","Parent the custom style to a material spring style so defaults are inherited","Validate both items exist before resolving, using obtainStyledAttributes in debug builds"],"exampleFix":"<!-- before -->\n<style name=\"MySpring\">\n  <item name=\"stiffness\">400</item>\n</style>\n<!-- after -->\n<style name=\"MySpring\">\n  <item name=\"stiffness\">400</item>\n  <item name=\"damping\">0.75</item>\n</style>","handlingStrategy":"validation","validationCode":"// Assert the style declares both spring values in a unit test\n@Test fun springStyleIsComplete() {\n    val context = ApplicationProvider.getApplicationContext<Context>()\n    val a = context.obtainStyledAttributes(R.style.MySpring, R.styleable.MaterialSpring)\n    assertTrue(a.hasValue(R.styleable.MaterialSpring_stiffness))\n    assertTrue(a.hasValue(R.styleable.MaterialSpring_damping))\n    a.recycle()\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Spring style missing damping\", e); useDefaultSpringForce() }","preventionTips":["Treat stiffness and damping as a pair; never ship one without the other","Use material parent styles so defaults are inherited","Prefer overriding existing material spring styles instead of authoring from scratch"],"tags":["android","material-components","animation","spring","style-attribute"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}