{"record":{"id":"105ae4a906d06291","repo":"material-components/material-components-android","slug":"attempted-to-get-shapeappearance-from-a-materialbu","errorCode":null,"errorMessage":"Attempted to get ShapeAppearance from a MaterialButton which has an overwritten background.","messagePattern":"Attempted to get ShapeAppearance from a MaterialButton which has an overwritten background\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/button/MaterialButton.java","lineNumber":1913,"sourceCode":"    }\n  }\n\n  /**\n   * Returns the {@link ShapeAppearance} used for this {@link MaterialButton}'s\n   * original drawables.\n   *\n   * <p>This {@link ShapeAppearance} can be modified to change the component's shape.\n   *\n   * @throws IllegalStateException if the MaterialButton's background has been overwritten.\n   * @hide\n   */\n  @NonNull\n  @RestrictTo(LIBRARY_GROUP)\n  public ShapeAppearance getShapeAppearance() {\n    if (isUsingOriginalBackground()) {\n      return materialButtonHelper.getShapeAppearance();\n    } else {\n      throw new IllegalStateException(\n          \"Attempted to get ShapeAppearance from a MaterialButton which has an\"\n              + \" overwritten background.\");\n    }\n  }\n\n  /**\n   * Sets the corner spring force for this {@link MaterialButton}.\n   *\n   * @param springForce The new {@link SpringForce} object.\n   * @hide\n   */\n  @RestrictTo(LIBRARY_GROUP)\n  public void setCornerSpringForce(@NonNull SpringForce springForce) {\n    materialButtonHelper.setCornerSpringForce(springForce);\n  }\n\n  /**\n   * Returns the corner spring force for this {@link MaterialButton}.","sourceCodeStart":1895,"sourceCodeEnd":1931,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/button/MaterialButton.java#L1895-L1931","documentation":"getShapeAppearance() is the @RestrictTo(LIBRARY_GROUP) getter that returns the ShapeAppearance of the button's original drawables. Symmetric with the other shape accessors, it throws IllegalStateException (MaterialButton.java:1913) when the button's background has been overwritten, because no original shape exists to read. App developers normally hit this only indirectly through library-internal code paths.","triggerScenarios":"Library-internal or forked code calling getShapeAppearance() on a MaterialButton that had its background replaced (android:background in XML, or setBackground/setBackgroundResource at runtime).","commonSituations":"A button style in the app theme sets android:background (e.g. for a legacy 9-patch or gradient), and a Material component or fork reads the child button's shape to compute corner geometry, crashing only for those themed buttons. Mirror of error 22 through the restricted API.","solutions":["Stop overriding android:background on MaterialButtons; express the look with app:backgroundTint, app:strokeColor, app:rippleColor and app:shapeAppearance attributes.","If the crash originates in library/fork code, report it upstream and temporarily remove the custom background on affected buttons.","In forks, guard internal getShapeAppearance() reads with isUsingOriginalBackground()."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (button.getBackground() instanceof MaterialShapeDrawable) {\n  ShapeAppearance appearance = button.getShapeAppearance();\n}","typeGuard":"static boolean hasOriginalShapeAppearance(MaterialButton b) {\n  return b.getBackground() instanceof MaterialShapeDrawable;\n}","tryCatchPattern":"try { return button.getShapeAppearance(); } catch (IllegalStateException e) { return null; }","preventionTips":["Avoid restricted APIs in app code; use getShapeAppearanceModel().","Guard any internal read with a MaterialShapeDrawable background check.","Report fork-internal crashes upstream with the button's XML."],"tags":["android","material-components","materialbutton","shape","restricted-api","background"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}