greenrobot/EventBus · error · RuntimeException
Failure event class must have a constructor with one paramet
Error message
Failure event class must have a constructor with one parameter of type Throwable
What it means
Thrown as RuntimeException from the AsyncExecutor constructor when failureEventType.getConstructor(Throwable.class) throws NoSuchMethodException. AsyncExecutor's contract: when a RunnableEx passed to execute() throws, AsyncExecutor instantiates the configured failure event class with new FailureEvent(Throwable cause) and posts it. The constructor lookup happens once at AsyncExecutor creation; a failure event without a public single-Throwable constructor makes the mechanism unusable, so construction fails fast.
Source
Thrown at EventBus/src/org/greenrobot/eventbus/util/AsyncExecutor.java:107
}
public static AsyncExecutor create() {
return new Builder().build();
}
private final Executor threadPool;
private final Constructor<?> failureEventConstructor;
private final EventBus eventBus;
private final Object scope;
private AsyncExecutor(Executor threadPool, EventBus eventBus, Class<?> failureEventType, Object scope) {
this.threadPool = threadPool;
this.eventBus = eventBus;
this.scope = scope;
try {
failureEventConstructor = failureEventType.getConstructor(Throwable.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(
"Failure event class must have a constructor with one parameter of type Throwable", e);
}
}
/** Posts an failure event if the given {@link RunnableEx} throws an Exception. */
public void execute(final RunnableEx runnable) {
threadPool.execute(() -> {
try {
runnable.run();
} catch (Exception e) {
Object event;
try {
event = failureEventConstructor.newInstance(e);
} catch (Exception e1) {
eventBus.getLogger().log(Level.SEVERE, "Original exception:", e);
throw new RuntimeException("Could not create failure event", e1);
}
if (event instanceof HasExecutionScope) {View on GitHub (pinned to 0194926b3b)
Solutions
- Add a public constructor taking exactly one Throwable to the failure event class: public FailureEvent(Throwable throwable) { this.cause = throwable; }
- In Kotlin: class FailureEvent(val throwable: Throwable) (primary constructor works) or add a secondary constructor
- Prefer subclassing the provided org.greenrobot.eventbus.util.ThrowableFailureEvent which already defines the required constructor
Example fix
// before
public class MyFailureEvent {
public String message;
public MyFailureEvent(String message) { this.message = message; } // no Throwable ctor -> throws
}
// after
public class MyFailureEvent extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
public MyFailureEvent(Throwable throwable) { super(throwable); }
} Defensive patterns
Strategy: validation
Validate before calling
// Verify the failure event contract before building the executor
try {
failureEventType.getConstructor(Throwable.class);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
failureEventType.getName() + " needs a public constructor taking exactly one Throwable", e);
}
AsyncExecutor exec = AsyncExecutor.builder()
.eventBus(EventBus.getDefault())
.failureEventType(failureEventType)
.buildForScope(this); Prevention
- Extend org.greenrobot.eventbus.util.ThrowableFailureEvent instead of writing custom classes
- Write a one-line unit test asserting getConstructor(Throwable.class) succeeds for your failure event
When it happens
Trigger: Building an AsyncExecutor via AsyncExecutor.builder().eventBus(bus).failureEventTypeId / .buildForScope(scope) with a failure event class that has no constructor, a multi-arg constructor, a (String) constructor, or a non-public (private/protected/package-private) Throwable constructor.
Common situations: Writing a custom failure event with extra fields and forgetting the Throwable constructor; Kotlin data classes whose only constructor takes additional parameters; making the Throwable constructor private for a factory-pattern class; reusing an arbitrary event class not designed for AsyncExecutor.
Related errors
- Could not create failure event
- It looks like you are using EventBus on Android, make sure t
- Subscriber ${subscriber.getClass()} already registered to ev
- This method may only be called from inside event handling me
- Event may not be null
AI-assisted analysis of greenrobot/EventBus@0194926b3b (2026-08-14).
Data as JSON: /api/errors/2584e16ff020c3a3.
Report an issue: GitHub.