hackware1993/MagicIndicator · error · IllegalArgumentException
x badge rule is wrong.
Error message
x badge rule is wrong.
What it means
BadgePagerTitleView.setXBadgeRule() validates that the BadgeRule's anchor is one of the X-axis anchors (LEFT, RIGHT, CONTENT_LEFT, CONTENT_RIGHT, CENTER_X, LEFT_EDGE_CENTER_X, RIGHT_EDGE_CENTER_Y-family X anchors). Passing a rule whose anchor is a Y-axis anchor (TOP, BOTTOM, CENTER_Y, etc.) throws IllegalArgumentException. The library enforces axis correctness at set time.
Solutions
- Use an X-axis anchor in the BadgeRule passed to setXBadgeRule: LEFT, RIGHT, CONTENT_LEFT, CONTENT_RIGHT, CENTER_X, LEFT_EDGE_CENTER_X, or RIGHT_EDGE_CENTER_X
- Move Y-axis anchors (TOP, BOTTOM, CONTENT_TOP, CONTENT_BOTTOM, CENTER_Y, TOP_EDGE_CENTER_Y, BOTTOM_EDGE_CENTER_Y) to setYBadgeRule instead
- If the rule is built dynamically, validate badgeRule.getAnchor() against the X anchors before calling setXBadgeRule
Example fix
// before badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CENTER_Y, 0)); // after badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CENTER_X, 0));
Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidXAnchor(@BadgeAnchor int anchor) {
return anchor == BadgeAnchor.LEFT
|| anchor == BadgeAnchor.RIGHT
|| anchor == BadgeAnchor.CONTENT_LEFT
|| anchor == BadgeAnchor.CONTENT_RIGHT
|| anchor == BadgeAnchor.CENTER_X
|| anchor == BadgeAnchor.LEFT_EDGE_CENTER_X
|| anchor == BadgeAnchor.RIGHT_EDGE_CENTER_X;
}
// before calling:
if (isValidXAnchor(rule.getAnchor())) view.setXBadgeRule(rule); Type guard
static boolean isXBadgeRule(BadgeRule rule) {
return rule != null && isValidXAnchor(rule.getAnchor());
} Try / catch
try {
badgePagerTitleView.setXBadgeRule(rule);
} catch (IllegalArgumentException e) {
Log.w("MagicIndicator", "Bad x 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 setXBadgeRule(new BadgeRule(BadgeAnchor.TOP, offset)) or any BadgeRule whose anchor is BadgeAnchor.BOTTOM, CONTENT_TOP, CONTENT_BOTTOM, CENTER_Y, TOP_EDGE_CENTER_Y, or BOTTOM_EDGE_CENTER_Y.
Common situations: Swapping the arguments when configuring a badge (using the Y anchor in setXBadgeRule), refactoring shared BadgeRule-building code between x and y setters, or copy-pasting a y rule into the x setter.
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/85b4f339895b10ff.
Report an issue: GitHub.
Appendix: source
Thrown at magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/badge/BadgePagerTitleView.java:188
}
return getBottom();
}
public BadgeRule getXBadgeRule() {
return mXBadgeRule;
}
public void setXBadgeRule(BadgeRule badgeRule) {
if (badgeRule != null) {
BadgeAnchor anchor = badgeRule.getAnchor();
if (anchor != BadgeAnchor.LEFT
&& anchor != BadgeAnchor.RIGHT
&& anchor != BadgeAnchor.CONTENT_LEFT
&& anchor != BadgeAnchor.CONTENT_RIGHT
&& anchor != BadgeAnchor.CENTER_X
&& anchor != BadgeAnchor.LEFT_EDGE_CENTER_X
&& anchor != BadgeAnchor.RIGHT_EDGE_CENTER_X) {
throw new IllegalArgumentException("x badge rule is wrong.");
}
}
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_YView on GitHub (pinned to fe22c7dc45)