JakeWharton/butterknife · error · IllegalStateException

@BindFont style must be NORMAL, BOLD, ITALIC, or BOLD_ITALIC

Error message

@BindFont style must be NORMAL, BOLD, ITALIC, or BOLD_ITALIC. (

What it means

Thrown by the reflection-based ButterKnife runtime when the style attribute of @BindFont is not one of Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, or Typeface.BOLD_ITALIC. After loading the font family, the binder switches on the style constant; an unrecognized value falls into the default branch and aborts binding.

Source

Thrown at butterknife-reflect/src/main/java/butterknife/ButterKnife.java:593

    int id = bindFont.value();
    int style = bindFont.style();
    Context context = source.getContext();

    Class<?> fieldType = field.getType();
    Object value;
    if (fieldType == Typeface.class) {
      Typeface font = ResourcesCompat.getFont(context, id);
      switch (style) {
        case Typeface.NORMAL:
          value = font;
          break;
        case Typeface.BOLD:
        case Typeface.ITALIC:
        case Typeface.BOLD_ITALIC:
          value = Typeface.create(font, style);
          break;
        default:
          throw new IllegalStateException(
              "@BindFont style must be NORMAL, BOLD, ITALIC, or BOLD_ITALIC. ("
                  + field.getDeclaringClass().getName()
                  + '.'
                  + field.getName()
                  + ')');
      }
    } else {
      throw new IllegalStateException("@BindFont field type must be 'Typeface'. ("
          + field.getDeclaringClass().getName()
          + '.'
          + field.getName()
          + ')');
    }
    trySet(field, target, value);

    return Unbinder.EMPTY;
  }

View on GitHub (pinned to fcdebedf32)

Solutions

  1. Use one of the named constants: Typeface.NORMAL, Typeface.BOLD, Typeface.ITALIC, or Typeface.BOLD_ITALIC in the @BindFont declaration.
  2. If the annotation took a bad constant from another class, replace it with the Typeface constant.
  3. Switch to butterknife-compiler so an out-of-range style fails the build.

Example fix

// before
@BindFont(value = R.font.sans, style = 7) Typeface font;

// after
@BindFont(value = R.font.sans, style = Typeface.BOLD_ITALIC) Typeface font;
Defensive patterns

Strategy: validation

Validate before calling

int style = fontAnnotation.style();
if (style != Typeface.NORMAL && style != Typeface.BOLD
    && style != Typeface.ITALIC && style != Typeface.BOLD_ITALIC) {
  throw new IllegalArgumentException("Invalid @BindFont style: " + style);
}

Type guard

static boolean isValidBindFontStyle(int style) {
  return style == Typeface.NORMAL || style == Typeface.BOLD
      || style == Typeface.ITALIC || style == Typeface.BOLD_ITALIC;
}

Prevention

When it happens

Trigger: ButterKnife.bind(...) via butterknife-reflect on a field with `@BindFont(value = R.font.x, style = 3)` or any style constant outside {0,1,2,3} — typically a hand-written constant, a typo'd constant, or a style value computed at runtime via a non-final variable.

Common situations: Passing Typeface.Style constants from android.R.attr or custom values, or copy-pasting a style int from another API (e.g. Paint typeface flags). The compiler path validates the style is a compile-time constant in range; reflect defers the failure to bind time.

Related errors


AI-assisted analysis of JakeWharton/butterknife@fcdebedf32 (2026-08-14). Data as JSON: /api/errors/4645dfee6d007d3f. Report an issue: GitHub.