{"record":{"id":"ec1829c6dc9c1417","repo":"greenrobot/EventBus","slug":"subscribe-method-methodname-must-have-exactly-1","errorCode":null,"errorMessage":"@Subscribe method ${methodName}must have exactly 1 parameter but has ${parameterTypes.length}","messagePattern":"@Subscribe method (.+?)must have exactly 1 parameter but has (.+?)","errorType":"exception","errorClass":"EventBusException","httpStatus":null,"severity":"error","filePath":"EventBus/src/org/greenrobot/eventbus/SubscriberMethodFinder.java","lineNumber":186,"sourceCode":"            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)) {\n                    String methodName = method.getDeclaringClass().getName() + \".\" + method.getName();\n                    throw new EventBusException(\"@Subscribe method \" + methodName +\n                            \"must have exactly 1 parameter but has \" + parameterTypes.length);\n                }\n            } else if (strictMethodVerification && method.isAnnotationPresent(Subscribe.class)) {\n                String methodName = method.getDeclaringClass().getName() + \".\" + method.getName();\n                throw new EventBusException(methodName +\n                        \" is a illegal @Subscribe method: must be public, non-static, and non-abstract\");\n            }\n        }\n    }\n\n    static void clearCaches() {\n        METHOD_CACHE.clear();\n    }\n\n    static class FindState {\n        final List<SubscriberMethod> subscriberMethods = new ArrayList<>();\n        final Map<Class, Object> anyMethodByEventType = new HashMap<>();\n        final Map<String, Class> subscriberClassByMethodKey = new HashMap<>();","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/SubscriberMethodFinder.java#L168-L204","documentation":"Thrown during method verification in SubscriberMethodFinder when strictMethodVerification is enabled (EventBusBuilder.strictMethodVerification, default true) and a method carries @Subscribe but does not have exactly one parameter. EventBus dispatches a single event object per call, so a subscriber method must declare exactly one event-type parameter; zero or 2+ parameters cannot be wired. Note the message text has a missing space: '...methodName must have exactly 1 parameter but has N'.","triggerScenarios":"Declaring @Subscribe void onEvent() with no args, or @Subscribe void onEvent(A a, B b) with two; enabling strictMethodVerification and registering a class containing such a method; the check fires during register() while scanning the class.","commonSituations":"Copy-paste of a regular callback into a subscriber; adding a second 'context' or 'tag' parameter to a handler; migrating from other bus libraries that allow extra parameters; leftover debug overloads annotated by accident.","solutions":["Change the method to take exactly one event parameter: @Subscribe public void onEvent(MessageEvent event)","If two pieces of data are needed, wrap them in a single event class holding both fields","Remove the @Subscribe annotation from methods that are not handlers"],"exampleFix":"// before\n@Subscribe\npublic void onEvent(MessageEvent event, Context ctx) { ... } // 2 params -> throws\n\n// after\npublic class MessageEvent { public final String text; public final Context ctx; ... }\n\n@Subscribe\npublic void onEvent(MessageEvent event) { ... }","handlingStrategy":"validation","validationCode":"// CI check: every @Subscribe method has exactly one parameter\nfor (Method m : subscriberClass.getDeclaredMethods()) {\n    Subscribe ann = m.getAnnotation(Subscribe.class);\n    if (ann != null && m.getParameterCount() != 1) {\n        throw new IllegalStateException(\"@Subscribe method \" + m + \" must have exactly 1 parameter\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt a project convention: one event parameter only, wrap extra data in the event class","Enable strictMethodVerification during development so mistakes fail at register time"],"tags":["eventbus","annotation","method-signature","validation"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}