{"record":{"id":"94c797e3ef79c4d8","repo":"greenrobot/EventBus","slug":"could-not-inspect-methods-of-clazz-getname-p","errorCode":null,"errorMessage":"Could not inspect methods of ${clazz.getName()}. Please make this class visible to EventBus annotation processor to avoid reflection.","messagePattern":"Could not inspect methods of (.+?)\\. Please make this class visible to EventBus annotation processor to avoid reflection\\.","errorType":"exception","errorClass":"EventBusException","httpStatus":null,"severity":"error","filePath":"EventBus/src/org/greenrobot/eventbus/SubscriberMethodFinder.java","lineNumber":166,"sourceCode":"    }\n\n    private void findUsingReflectionInSingleClass(FindState findState) {\n        Method[] methods;\n        try {\n            // This is faster than getMethods, especially when subscribers are fat classes like Activities\n            methods = findState.clazz.getDeclaredMethods();\n        } catch (Throwable th) {\n            // Workaround for java.lang.NoClassDefFoundError, see https://github.com/greenrobot/EventBus/issues/149\n            try {\n                methods = findState.clazz.getMethods();\n            } catch (LinkageError error) { // super class of NoClassDefFoundError to be a bit more broad...\n                String msg = \"Could not inspect methods of \" + findState.clazz.getName();\n                if (ignoreGeneratedIndex) {\n                    msg += \". Please consider using EventBus annotation processor to avoid reflection.\";\n                } else {\n                    msg += \". Please make this class visible to EventBus annotation processor to avoid reflection.\";\n                }\n                throw new EventBusException(msg, error);\n            }\n            findState.skipSuperClasses = true;\n        }\n        for (Method method : methods) {\n            int modifiers = method.getModifiers();\n            if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & MODIFIERS_IGNORE) == 0) {\n                Class<?>[] parameterTypes = method.getParameterTypes();\n                if (parameterTypes.length == 1) {\n                    Subscribe subscribeAnnotation = method.getAnnotation(Subscribe.class);\n                    if (subscribeAnnotation != null) {\n                        Class<?> eventType = parameterTypes[0];\n                        if (findState.checkAdd(method, eventType)) {\n                            ThreadMode threadMode = subscribeAnnotation.threadMode();\n                            findState.subscriberMethods.add(new SubscriberMethod(method, eventType, threadMode,\n                                    subscribeAnnotation.priority(), subscribeAnnotation.sticky()));\n                        }\n                    }\n                } else if (strictMethodVerification && method.isAnnotationPresent(Subscribe.class)) {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/SubscriberMethodFinder.java#L148-L184","documentation":"Thrown by SubscriberMethodFinder.findUsingReflectionInPackage/FindState when both Class.getDeclaredMethods() and the fallback Class.getMethods() fail with a LinkageError (superclass of NoClassDefFoundError — see greenrobot/EventBus#149). Reflection needs to load a method's parameter/return types to enumerate methods; if any referenced type is missing from the classpath at that moment, the JVM throws NoClassDefFoundError and EventBus wraps it, telling you to make the class visible to the annotation processor so reflection (and thus the fragile linkage) is avoided entirely.","triggerScenarios":"A subscriber (or its superclass) has a method signature referencing a class not on the runtime classpath — e.g. methods referencing optional SDK classes, stubbed android.jar in unit tests, or classes provided by a different flavor/build variant; NoClassDefFoundError raised lazily while getDeclaredMethods() resolves parameter types.","commonSituations":"JVM unit tests of Android code where subscriber signatures mention Android classes not stubbed by the test runner; optional-dependency patterns; fat-jar packaging that excludes transitive classes referenced in method descriptors; proguard-assisted removal of classes still referenced in kept method signatures.","solutions":["Add the missing class (named in the LinkageError/NoClassDefFoundError cause) to the runtime/test classpath","Enable the EventBus annotation processor + subscriber index so methods are resolved at compile time: annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.3.1' and EventBus.builder().addIndex(new MySubscriberInfoIndex(...))","In JVM tests, use Robolectric or add the missing android stubs so method resolution succeeds","Avoid subscriber method signatures referencing optional/variant-specific types; wrap them in types that are always present"],"exampleFix":"// before: JVM unit test fails with EventBusException wrapping NoClassDefFoundError: android/net/Uri\npublic class HeadlinesSubscriber {\n    @Subscribe public void onUri(android.netUri uri) { ... }\n}\n\n// after: test-only stub or Robolectric\ntestImplementation 'org.robolectric:robolectric:4.11'\n// or remove the Android type from the subscriber signature\n@Subscribe public void onUriEvent(UriEvent event) { ... }","handlingStrategy":"fallback","validationCode":"// Pre-flight: can we reflect over the class without linkage errors?\ntry {\n    clazz.getDeclaredMethods();\n} catch (LinkageError error) {\n    throw new IllegalStateException(\n        \"Class \" + clazz.getName() + \" references missing types; fix classpath or use subscriber index\", error);\n}","typeGuard":null,"tryCatchPattern":"try {\n    EventBus.getDefault().register(subscriber);\n} catch (EventBusException e) {\n    if (e.getCause() instanceof LinkageError) {\n        // missing dependency at runtime: report which class failed to link\n        Log.e(TAG, \"Linkage problem scanning \" + subscriber.getClass().getName(), e);\n        return; // skip registration instead of crashing the app\n    }\n    throw e;\n}","preventionTips":["Prefer the generated subscriber index over runtime reflection","Keep subscriber method signatures free of optional/variant-only types","Run JVM unit tests against the same classpath shape as production"],"tags":["eventbus","reflection","classpath","noclassdeffounderror","annotation-processor"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}