{"record":{"id":"b2e04be7bd4e447e","repo":"greenrobot/EventBus","slug":"unexpected-exception","errorCode":null,"errorMessage":"Unexpected exception","messagePattern":"Unexpected exception","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"EventBus/src/org/greenrobot/eventbus/EventBus.java","lineNumber":521,"sourceCode":"     * subscriber unregistered. This is particularly important for main thread delivery and registrations bound to the\n     * live cycle of an Activity or Fragment.\n     */\n    void invokeSubscriber(PendingPost pendingPost) {\n        Object event = pendingPost.event;\n        Subscription subscription = pendingPost.subscription;\n        PendingPost.releasePendingPost(pendingPost);\n        if (subscription.active) {\n            invokeSubscriber(subscription, event);\n        }\n    }\n\n    void invokeSubscriber(Subscription subscription, Object event) {\n        try {\n            subscription.subscriberMethod.method.invoke(subscription.subscriber, event);\n        } catch (InvocationTargetException e) {\n            handleSubscriberException(subscription, event, e.getCause());\n        } catch (IllegalAccessException e) {\n            throw new IllegalStateException(\"Unexpected exception\", e);\n        }\n    }\n\n    private void handleSubscriberException(Subscription subscription, Object event, Throwable cause) {\n        if (event instanceof SubscriberExceptionEvent) {\n            if (logSubscriberExceptions) {\n                // Don't send another SubscriberExceptionEvent to avoid infinite event recursion, just log\n                logger.log(Level.SEVERE, \"SubscriberExceptionEvent subscriber \" + subscription.subscriber.getClass()\n                        + \" threw an exception\", cause);\n                SubscriberExceptionEvent exEvent = (SubscriberExceptionEvent) event;\n                logger.log(Level.SEVERE, \"Initial event \" + exEvent.causingEvent + \" caused exception in \"\n                        + exEvent.causingSubscriber, exEvent.throwable);\n            }\n        } else {\n            if (throwSubscriberException) {\n                throw new EventBusException(\"Invoking subscriber failed\", cause);\n            }\n            if (logSubscriberExceptions) {","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/EventBus.java#L503-L539","documentation":"Thrown as IllegalStateException from invokeSubscriber(Subscription, Object) when Method.invoke fails with IllegalAccessException. This means reflection could not access the @Subscribe method: the method is not public (or the class is not accessible) at runtime even though it was discovered/registered. InvocationTargetException (the subscriber's own exception) is handled separately by handleSubscriberException; IllegalAccessException is purely an access problem and is treated as an unexpected, non-recoverable state.","triggerScenarios":"A @Subscribe method that was public at compile time but got shrunk/obfuscated to package-private at runtime (aggressive ProGuard/R8 optimization like -allowaccessmodification combined with missing keep rules); a subscriber class loaded by a different classloader making its package inaccessible; runtime instrumentation altering modifiers.","commonSituations":"Release builds of Android apps with ProGuard/R8 stripping or renaming @Subscribe methods without the standard EventBus keep rules; modularized apps with non-exported packages; bytecode transformers (Jacoco offline-instrumentation edge cases, aspect agents) changing visibility.","solutions":["Add the standard EventBus ProGuard rules: -keepattributes *Annotation*,Signature and -keepclassmembers class * { @org.greenrobot.eventbus.Subscribe <methods>; }","Check the stack trace for the method named in the reflection frame and verify it is public and its class is public at runtime","Disable -allowaccessmodification or add explicit -keep for the affected subscriber classes, then rebuild the release variant","If using a custom subscriber index, ensure the index classes are kept too"],"exampleFix":"# before (proguard-rules.pro has no EventBus rules)\n# -> release build throws IllegalStateException: Unexpected exception\n\n# after (proguard-rules.pro)\n-keepattributes *Annotation*,Signature\n-keepclassmembers class ** {\n    @org.greenrobot.eventbus.Subscribe <methods>;\n}","handlingStrategy":"try-catch","validationCode":"// At startup, verify annotated subscriber methods are reflectively accessible\nfor (Method m : subscriberClass.getDeclaredMethods()) {\n    if (m.isAnnotationPresent(Subscribe.class)\n            && !Modifier.isPublic(m.getModifiers())) {\n        throw new IllegalStateException(\"Non-public @Subscribe method: \" + m);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    EventBus.getDefault().post(event);\n} catch (IllegalStateException e) {\n    if (\"Unexpected exception\".equals(e.getMessage()) && e.getCause() instanceof IllegalAccessException) {\n        // access problem: report ProGuard/visibility misconfiguration\n        crashReporter.report(new IllegalStateException(\"Subscriber method not accessible (ProGuard?)\", e));\n        return;\n    }\n    throw e;\n}","preventionTips":["Ship the canonical EventBus ProGuard keep rules in every minified build","Smoke-test the release/minified variant, not only debug","Keep @Subscribe methods public instance methods"],"tags":["eventbus","reflection","proguard","obfuscation","android"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}