{"record":{"id":"657cb8d50ebd3baa","repo":"material-components/material-components-android","slug":"custombadgeparent-must-be-a-framelayout","errorCode":null,"errorMessage":"customBadgeParent must be a FrameLayout","messagePattern":"customBadgeParent must be a FrameLayout","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/badge/BadgeDrawable.java","lineNumber":373,"sourceCode":"    restoreState();\n  }\n\n  /**\n   * Calculates and updates this badge's center coordinates based on its anchor's bounds. Internally\n   * also updates this {@code BadgeDrawable BadgeDrawable's} bounds, because they are dependent on\n   * the center coordinates. For pre API-18, coordinates will be calculated relative to {@code\n   * customBadgeParent} because the {@code BadgeDrawable} will be set as the parent's foreground.\n   *\n   * @param anchorView This badge's anchor.\n   * @param customBadgeParent An optional parent view that will set this {@code BadgeDrawable} as\n   *     its foreground.\n   * @deprecated use {@link BadgeDrawable#updateBadgeCoordinates(View, FrameLayout)} instead.\n   */\n  @Deprecated\n  public void updateBadgeCoordinates(\n      @NonNull View anchorView, @Nullable ViewGroup customBadgeParent) {\n    if (!(customBadgeParent instanceof FrameLayout)) {\n      throw new IllegalArgumentException(\"customBadgeParent must be a FrameLayout\");\n    }\n    updateBadgeCoordinates(anchorView, (FrameLayout) customBadgeParent);\n  }\n\n  /**\n   * Calculates and updates this badge's center coordinates based on its anchor's bounds. Internally\n   * also updates this {@code BadgeDrawable BadgeDrawable's} bounds, because they are dependent on\n   * the center coordinates.\n   *\n   * @param anchorView This badge's anchor.\n   */\n  public void updateBadgeCoordinates(@NonNull View anchorView) {\n    updateBadgeCoordinates(anchorView, null);\n  }\n\n  /**\n   * Calculates and updates this badge's center coordinates based on its anchor's bounds. Internally\n   * also updates this {@code BadgeDrawable BadgeDrawable's} bounds, because they are dependent on","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/badge/BadgeDrawable.java#L355-L391","documentation":"The deprecated BadgeDrawable.updateBadgeCoordinates(View, ViewGroup) requires the custom badge parent to be a FrameLayout, because the badge is set as that parent's foreground and its center coordinates are computed against the parent's bounds. Any non-FrameLayout argument (including null) throws IllegalArgumentException. Use the non-deprecated overload taking a FrameLayout, or updateBadgeCoordinates(View).","triggerScenarios":"Calling the deprecated updateBadgeCoordinates(anchorView, customBadgeParent) where customBadgeParent is null (null fails the instanceof check), a LinearLayout, RelativeLayout, or any other non-FrameLayout ViewGroup.","commonSituations":"Migrating older badge code that passed an arbitrary parent view; passing null intending 'no custom parent' (null is rejected by this overload); wrapping the anchor in a ConstraintLayout and handing that in as the custom parent.","solutions":["Switch to the non-deprecated updateBadgeCoordinates(View anchorView) when no custom parent is needed.","If a custom parent is required, pass a FrameLayout (e.g. wrap the anchor in one) or call the FrameLayout-typed overload updateBadgeCoordinates(View, FrameLayout).","Never pass null as customBadgeParent to the deprecated overload — it throws; use the single-arg overload instead."],"exampleFix":"// before (deprecated, throws for non-FrameLayout or null)\nbadgeDrawable.updateBadgeCoordinates(anchor, null);\n\n// after\nbadgeDrawable.updateBadgeCoordinates(anchor);\n// or, with a custom parent:\nbadgeDrawable.updateBadgeCoordinates(anchor, frameLayoutParent);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"if (customBadgeParent instanceof FrameLayout) {\n  badge.updateBadgeCoordinates(anchor, (FrameLayout) customBadgeParent);\n} else {\n  badge.updateBadgeCoordinates(anchor); // no custom parent\n}","tryCatchPattern":null,"preventionTips":["Prefer the non-deprecated overloads; treat the ViewGroup overload as legacy.","Never pass null as customBadgeParent — null fails the instanceof check."],"tags":["badge","deprecated-api","illegal-argument","framelayout"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}