{"record":{"id":"11f553baf6bf28b1","repo":"material-components/material-components-android","slug":"a-materialspring-style-must-have-stiffness-value","errorCode":null,"errorMessage":"A MaterialSpring style must have stiffness value.","messagePattern":"A MaterialSpring style must have stiffness value\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/motion/MotionUtils.java","lineNumber":70,"sourceCode":"   * resolved Material spring attribute\n   */\n  @NonNull\n  public static SpringForce resolveThemeSpringForce(\n      @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.","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/motion/MotionUtils.java#L52-L88","documentation":"MotionUtils.resolveAsSpringForce(Callback) reads a spring style (attr MaterialSpring) via obtainStyledAttributes and requires both stiffness and damping. The default value sent to TypedArray.getFloat is Float.MIN_VALUE, so if the resolved style did not define stiffness, the sentinel is returned and the method throws IllegalArgumentException. This exists because SpringForce cannot be meaningfully constructed without a stiffness (and damping) value.","triggerScenarios":"Calling MotionUtils.resolveAsSpringForce (directly or indirectly, e.g. via MotionUtils or a component resolving ?attr/materialSpring style attributes) with a style resource that lacks the MaterialSpring_stiffness item; also triggered when the TypedValue resolved from attrResId points to a resource that is not actually a MaterialSpring style, so no stiffness is found.","commonSituations":"App defines a custom spring style overriding the material theme attribute but forgets <item name=\"stiffness\">; typo in styleable item name; using an @style that only sets damping; version changes where Material item names were renamed.","solutions":["Add <item name=\"stiffness\">[value]</item> to the style referenced by the spring attribute","Verify the style parent is a valid Material spring style (e.g. Widget.Material.Motion.Base to copy defaults)","Confirm the attribute resolves to an @style resource and not a malformed reference","Check the resolve fallback: if tv == null, the defStyleAttr/defStyleRes chain must still supply stiffness"],"exampleFix":"<!-- before -->\n<style name=\"MySpring\" parent=\"Widget.Material.Components.Spring\">\n  <item name=\"damping\">0.8</item>\n</style>\n<!-- after -->\n<style name=\"MySpring\" parent=\"Widget.Material.Components.Spring\">\n  <item name=\"stiffness\">300</item>\n  <item name=\"damping\">0.8</item>\n</style>","handlingStrategy":"validation","validationCode":"// Debug-build guard before resolving a spring style\nfun Context.hasSpringStiffness(attrResId: Int): Boolean {\n    val tv = TypedValue()\n    if (theme.resolveAttribute(attrResId, tv, true) && tv.resourceId != 0) {\n        val a = obtainStyledAttributes(tv.resourceId, intArrayOf(android.R.attr.stiffness))\n        val has = a.hasValue(0)\n        a.recycle()\n        return has\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Spring style missing stiffness; fix style resource\", e); fallbackToDefaultSpring() }","preventionTips":["Always define both stiffness and damping items in custom MaterialSpring styles","Parent custom spring styles to a material spring style to inherit defaults","Add a lint/unit test that parses your motion styles and asserts required items"],"tags":["android","material-components","animation","spring","style-attribute"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}