hackware1993/MagicIndicator · error · IllegalArgumentException
y badge rule is wrong.
Error message
y badge rule is wrong.
What it means
BadgePagerTitleView.setYBadgeRule() validates that the BadgeRule's anchor is one of the Y-axis anchors (TOP, BOTTOM, CONTENT_TOP, CONTENT_BOTTOM, CENTER_Y, TOP_EDGE_CENTER_Y, BOTTOM_EDGE_CENTER_Y). Passing a rule anchored on an X-axis anchor throws IllegalArgumentException. This mirrors the X-axis check and keeps badge positioning well-defined.
Solutions
- Use a Y-axis anchor in the BadgeRule passed to setYBadgeRule: TOP, BOTTOM, CONTENT_TOP, CONTENT_BOTTOM, CENTER_Y, TOP_EDGE_CENTER_Y, or BOTTOM_EDGE_CENTER_Y
- Move X-axis anchors (LEFT, RIGHT, CONTENT_LEFT, CONTENT_RIGHT, CENTER_X, LEFT_EDGE_CENTER_X, RIGHT_EDGE_CENTER_X) to setXBadgeRule instead
- If the rule is built dynamically, validate badgeRule.getAnchor() against the Y anchors before calling setYBadgeRule
Example fix
// before badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.RIGHT, 0)); // after badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.BOTTOM, 0));
Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidYAnchor(@BadgeAnchor int anchor) {
return anchor == BadgeAnchor.TOP
|| anchor == BadgeAnchor.BOTTOM
|| anchor == BadgeAnchor.CONTENT_TOP
|| anchor == BadgeAnchor.CONTENT_BOTTOM
|| anchor == BadgeAnchor.CENTER_Y
|| anchor == BadgeAnchor.TOP_EDGE_CENTER_Y
|| anchor == BadgeAnchor.BOTTOM_EDGE_CENTER_Y;
}
// before calling:
if (isValidYAnchor(rule.getAnchor())) view.setYBadgeRule(rule); Type guard
static boolean isYBadgeRule(BadgeRule rule) {
return rule != null && isValidYAnchor(rule.getAnchor());
} Try / catch
try {
badgePagerTitleView.setYBadgeRule(rule);
} catch (IllegalArgumentException e) {
Log.w("MagicIndicator", "Bad y badge rule anchor: " + rule.getAnchor(), e);
} Prevention
- Keep x and y BadgeRule construction in separate clearly-named helper methods
- Use the BadgeAnchor constants, never raw ints, so the IDE flags wrong-axis usage
- If building rules dynamically, check the anchor axis at build time
When it happens
Trigger: Calling setYBadgeRule(new BadgeRule(BadgeAnchor.LEFT, offset)) or any BadgeRule whose anchor is BadgeAnchor.LEFT, RIGHT, CONTENT_LEFT, CONTENT_RIGHT, CENTER_X, LEFT_EDGE_CENTER_X, or RIGHT_EDGE_CENTER_X.
Common situations: Copy-pasting an x badge rule into the y setter, misremembering which anchors belong to which axis, or generating anchors programmatically where the axis distinction is lost.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
AI-assisted analysis of hackware1993/MagicIndicator@fe22c7dc45 (2026-09-10).
Data as JSON: /api/errors/3932f00997a180e4.
Report an issue: GitHub.
Appendix: source
Thrown at magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/badge/BadgePagerTitleView.java:208
}
mXBadgeRule = badgeRule;
}
public BadgeRule getYBadgeRule() {
return mYBadgeRule;
}
public void setYBadgeRule(BadgeRule badgeRule) {
if (badgeRule != null) {
BadgeAnchor anchor = badgeRule.getAnchor();
if (anchor != BadgeAnchor.TOP
&& anchor != BadgeAnchor.BOTTOM
&& anchor != BadgeAnchor.CONTENT_TOP
&& anchor != BadgeAnchor.CONTENT_BOTTOM
&& anchor != BadgeAnchor.CENTER_Y
&& anchor != BadgeAnchor.TOP_EDGE_CENTER_Y
&& anchor != BadgeAnchor.BOTTOM_EDGE_CENTER_Y) {
throw new IllegalArgumentException("y badge rule is wrong.");
}
}
mYBadgeRule = badgeRule;
}
public boolean isAutoCancelBadge() {
return mAutoCancelBadge;
}
public void setAutoCancelBadge(boolean autoCancelBadge) {
mAutoCancelBadge = autoCancelBadge;
}
}
View on GitHub (pinned to fe22c7dc45)