{"record":{"id":"5af45ff157f13732","repo":"JakeWharton/butterknife","slug":"must-not-be-private-or-static","errorCode":null,"errorMessage":" must not be private or static","messagePattern":" must not be private or static","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"butterknife-reflect/src/main/java/butterknife/ButterKnife.java","lineNumber":982,"sourceCode":"    String who = \"method '\" + name + \"'\";\n    List<T> views = new ArrayList<>(ids.length);\n    for (int id : ids) {\n      if (isRequired) {\n        views.add((T) Utils.findRequiredViewAsType(source, id, who, cls));\n      } else {\n        T view = (T) Utils.findOptionalViewAsType(source, id, who, cls);\n        if (view != null) {\n          views.add(view);\n        }\n      }\n    }\n    return views;\n  }\n\n  private static <T extends AccessibleObject & Member> void validateMember(T object) {\n    int modifiers = object.getModifiers();\n    if ((modifiers & (PRIVATE | STATIC)) != 0) {\n      throw new IllegalStateException(object.getDeclaringClass().getName()\n          + \".\"\n          + object.getName()\n          + \" must not be private or static\");\n    }\n    if ((modifiers & PUBLIC) == 0) {\n      object.setAccessible(true);\n    }\n  }\n\n  /** Returns true when the return value should be propagated. Use a default otherwise. */\n  private static boolean validateReturnType(Method method, Class<?> expected) {\n    Class<?> returnType = method.getReturnType();\n    if (returnType == void.class) {\n      return false;\n    }\n    if (returnType != expected) {\n      String expectedType = \"'\" + expected.getName() + \"'\";\n      if (expected != void.class) {","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife-reflect/src/main/java/butterknife/ButterKnife.java#L964-L1000","documentation":"Thrown by ButterKnife's reflection binder (validateMember) when an annotated binding field or listener method is declared private or static. Reflection-based assignment and invocation require accessible, instance-level members, and ButterKnife's contract (shared with the annotation processor) forbids private/static bound members so generated and reflective paths behave identically.","triggerScenarios":"ButterKnife.bind(...) via butterknife-reflect on a class containing `private @BindView(R.id.title) TextView title;` or `static @OnClick(R.id.btn) void click()` — any bound member whose modifiers include PRIVATE or STATIC.","commonSituations":"Encapsulating-style developers mark fields private; refactoring moves an @OnClick handler into a static utility or companion method; Kotlin properties compiled to private backing fields with wrong visibility. The compiler path reports the same rule at build time, so this runtime form appears with butterknife-reflect (tests, libraries, Gradle experimental plugins).","solutions":["Remove `private` and `static` from the annotated field or method (package-private or public is fine).","For fields, use at least package-private visibility; for @OnClick/@On* methods make them non-static instance methods.","Switch to butterknife-compiler to get this as a compile-time error."],"exampleFix":"// before\nprivate @BindView(R.id.title) TextView title;\nstatic @OnClick(R.id.done) void onDone() { }\n\n// after\n@BindView(R.id.title) TextView title;\n@OnClick(R.id.done) void onDone() { }","handlingStrategy":"validation","validationCode":"for (Field f : targetClass.getDeclaredFields()) {\n  if (isBound(f)) {\n    int m = f.getModifiers();\n    if ((m & (Modifier.PRIVATE | Modifier.STATIC)) != 0) {\n      throw new IllegalStateException(f + \" must not be private or static\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep bound fields and @On* methods package-private or public and instance-level.","Avoid private visibility for ButterKnife members even in utility-style classes.","Switch to butterknife-compiler — same rule enforced at compile time."],"tags":["butterknife","reflection","visibility","static","annotation"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}