{"record":{"id":"1b0572a5ce14e423","repo":"JakeWharton/butterknife","slug":"must-not-be-private","errorCode":null,"errorMessage":" must not be private.","messagePattern":" must not be private\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":135,"sourceCode":"  @NonNull @UiThread\n  public static Unbinder bind(@NonNull Object target, @NonNull Dialog source) {\n    View sourceView = source.getWindow().getDecorView();\n    return bind(target, sourceView);\n  }\n\n  /**\n   * BindView annotated fields and methods in the specified {@code target} using the {@code source}\n   * {@link View} as the view root.\n   *\n   * @param target Target class for view binding.\n   * @param source View root on which IDs will be looked up.\n   */\n  @NonNull @UiThread\n  public static Unbinder bind(@NonNull Object target, @NonNull View source) {\n    List<Unbinder> unbinders = new ArrayList<>();\n    Class<?> targetClass = target.getClass();\n    if ((targetClass.getModifiers() & PRIVATE) != 0) {\n      throw new IllegalArgumentException(targetClass.getName() + \" must not be private.\");\n    }\n\n    while (true) {\n      String clsName = targetClass.getName();\n      if (clsName.startsWith(\"android.\") || clsName.startsWith(\"java.\")\n          || clsName.startsWith(\"androidx.\")) {\n        break;\n      }\n\n      for (Field field : targetClass.getDeclaredFields()) {\n        int unbinderStartingSize = unbinders.size();\n        Unbinder unbinder;\n\n        unbinder = parseBindView(target, field, source);\n        if (unbinder != null) unbinders.add(unbinder);\n\n        unbinder = parseBindViews(target, field, source);\n        if (unbinder != null) unbinders.add(unbinder);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L117-L153","documentation":"ButterKnife.bind(target, source) in the reflection-based butterknife-reflect module walks the class hierarchy and calls setAccessible(true) on annotated members. A private top-level (or local/anonymous) target class cannot be safely reflectively accessed from the binder machinery, so bind fails fast with an IllegalArgumentException before any binding happens.","triggerScenarios":"Calling ButterKnife.bind(new PrivateTarget(), view) where PrivateTarget is declared `private static class`; binding on an anonymous class instance created inside another class; Java 15+ hidden classes.","commonSituations":"Using butterknife-reflect (or the ReflectUnbinder path in tests) with nested private classes; refactoring a public binding class to private while keeping bind calls; IDE-generating a private inner class for a listener holder.","solutions":["Change the target class visibility from private to package-private or public (e.g. `static class MyHolder` instead of `private static class MyHolder`)","Move the binding fields/methods into a class with at least package visibility","Prefer the annotation-processor (generated binder) flavor of ButterKnife, which does not reflect on the target class itself"],"exampleFix":"// before\nprivate static class Header {\n  @BindView(R.id.title) TextView title;\n}\n\n// after\nstatic class Header {\n  @BindView(R.id.title) TextView title;\n}","handlingStrategy":"validation","validationCode":"Class<?> cls = target.getClass();\nif ((cls.getModifiers() & Modifier.PRIVATE) != 0) {\n  throw new IllegalArgumentException(\"Refuse to bind private class \" + cls.getName());\n}\nButterKnife.bind(target, source);","typeGuard":null,"tryCatchPattern":"try {\n  ButterKnife.bind(target, source);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().endsWith(\"must not be private.\")) {\n    logAndRecoverFromPrivateTarget(e); // e.g. skip binding for this target\n  } else {\n    throw e;\n  }\n}","preventionTips":["Never declare ButterKnife target classes private; use package-private or public","Avoid binding anonymous/local classes with butterknife-reflect","Add a lint/unit check that binding targets are not private"],"tags":["butterknife","runtime","reflection","visibility"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}