{"record":{"id":"7ff7e288ba64eaf8","repo":"greenrobot/EventBus","slug":"could-not-create-failure-event","errorCode":null,"errorMessage":"Could not create failure event","messagePattern":"Could not create failure event","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"EventBus/src/org/greenrobot/eventbus/util/AsyncExecutor.java","lineNumber":123,"sourceCode":"            failureEventConstructor = failureEventType.getConstructor(Throwable.class);\n        } catch (NoSuchMethodException e) {\n            throw new RuntimeException(\n                    \"Failure event class must have a constructor with one parameter of type Throwable\", e);\n        }\n    }\n\n    /** Posts an failure event if the given {@link RunnableEx} throws an Exception. */\n    public void execute(final RunnableEx runnable) {\n        threadPool.execute(() -> {\n            try {\n                runnable.run();\n            } catch (Exception e) {\n                Object event;\n                try {\n                    event = failureEventConstructor.newInstance(e);\n                } catch (Exception e1) {\n                    eventBus.getLogger().log(Level.SEVERE, \"Original exception:\", e);\n                    throw new RuntimeException(\"Could not create failure event\", e1);\n                }\n                if (event instanceof HasExecutionScope) {\n                    ((HasExecutionScope) event).setExecutionScope(scope);\n                }\n                eventBus.post(event);\n            }\n        });\n    }\n\n}\n","sourceCodeStart":105,"sourceCodeEnd":134,"githubUrl":"https://github.com/greenrobot/EventBus/blob/0194926b3bcf70cc0d7bfd3c5da16708dd5ab876/EventBus/src/org/greenrobot/eventbus/util/AsyncExecutor.java#L105-L134","documentation":"Thrown as RuntimeException from AsyncExecutor.execute()'s pool runnable when failureEventConstructor.newInstance(e) fails. Unlike error 14 (constructor missing, detected at build time), here the constructor exists but invoking it failed: it threw an exception itself, the class is abstract, the constructor is inaccessible at runtime, or argument matching broke (e.g. boxed primitive mismatch). The original runnable's exception is logged first ('Original exception:'), then this error propagates on the executor thread, likely crashing it.","triggerScenarios":"A failure-event constructor whose body throws (e.g. calls cause.getMessage() and NPEs on null message, or does further parsing); an abstract failure event class; a constructor that lost public visibility after obfuscation; constructor with side effects like posting to a dead bus.","commonSituations":"Custom failure events that try to enrich the throwable (calling getMessage()/parsing stack traces) and crash on odd throwables; release builds with R8 removing/altering constructor accessibility; abstract base failure events registered by mistake.","solutions":["Make the failure-event constructor trivial: only store the Throwable, do no parsing or derived computation in it","Ensure the class is concrete (not abstract) and its Throwable constructor is public","Add ProGuard keep rules for the failure event class if it breaks only in minified builds","Inspect the logged 'Original exception:' and the new exception's cause to see which constructor operation failed"],"exampleFix":"// before\npublic class MyFailureEvent extends ThrowableFailureEvent {\n    public MyFailureEvent(Throwable t) {\n        super(t);\n        this.code = Integer.parseInt(t.getMessage()); // throws NumberFormatException -> 'Could not create failure event'\n    }\n}\n\n// after\npublic class MyFailureEvent extends ThrowableFailureEvent {\n    public final String rawMessage;\n    public MyFailureEvent(Throwable t) {\n        super(t);\n        this.rawMessage = t.getMessage(); // store only, parse lazily in subscriber\n    }\n}","handlingStrategy":"fallback","validationCode":"// Probe instantiation once at setup (non-abstract, public ctor, ctor body safe)\ntry {\n    Object probe = failureEventType.getConstructor(Throwable.class)\n            .newInstance(new RuntimeException(\"probe\"));\n    if (probe == null) throw new IllegalStateException(\"instantiation returned null\");\n} catch (Exception e) {\n    throw new IllegalStateException(\"Failure event cannot be instantiated; keep its ctor trivial\", e);\n}","typeGuard":null,"tryCatchPattern":"// Wrap work submitted to AsyncExecutor so runnable failures never depend on ctor logic\nAsyncExecutor exec = AsyncExecutor.builder()\n        .eventBus(EventBus.getDefault())\n        .failureEventType(ThrowableFailureEvent.class) // known-good type\n        .buildForScope(this);\nexec.execute(() -> {\n    try {\n        doRiskyWork();\n    } catch (Exception e) {\n        EventBus.getDefault().post(new MySafeFailureEvent(e)); // own, trivial event\n    }\n});","preventionTips":["Keep failure-event constructors side-effect free: store the Throwable, nothing else","Use the built-in ThrowableFailureEvent unless you truly need a custom type"],"tags":["eventbus","asyncexecutor","reflection","failure-event","runtime"],"backgroundTag":null,"analyzedSha":"0194926b3bcf70cc0d7bfd3c5da16708dd5ab876","analyzedAt":"2026-08-14T10:41:08.786Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}