greenrobot/EventBus · error · RuntimeException
Could not create failure event
Error message
Could not create failure event
What it means
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.
Source
Thrown at EventBus/src/org/greenrobot/eventbus/util/AsyncExecutor.java:123
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) {
((HasExecutionScope) event).setExecutionScope(scope);
}
eventBus.post(event);
}
});
}
}
View on GitHub (pinned to 0194926b3b)
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
Example fix
// before
public class MyFailureEvent extends ThrowableFailureEvent {
public MyFailureEvent(Throwable t) {
super(t);
this.code = Integer.parseInt(t.getMessage()); // throws NumberFormatException -> 'Could not create failure event'
}
}
// after
public class MyFailureEvent extends ThrowableFailureEvent {
public final String rawMessage;
public MyFailureEvent(Throwable t) {
super(t);
this.rawMessage = t.getMessage(); // store only, parse lazily in subscriber
}
} Defensive patterns
Strategy: fallback
Validate before calling
// Probe instantiation once at setup (non-abstract, public ctor, ctor body safe)
try {
Object probe = failureEventType.getConstructor(Throwable.class)
.newInstance(new RuntimeException("probe"));
if (probe == null) throw new IllegalStateException("instantiation returned null");
} catch (Exception e) {
throw new IllegalStateException("Failure event cannot be instantiated; keep its ctor trivial", e);
} Try / catch
// Wrap work submitted to AsyncExecutor so runnable failures never depend on ctor logic
AsyncExecutor exec = AsyncExecutor.builder()
.eventBus(EventBus.getDefault())
.failureEventType(ThrowableFailureEvent.class) // known-good type
.buildForScope(this);
exec.execute(() -> {
try {
doRiskyWork();
} catch (Exception e) {
EventBus.getDefault().post(new MySafeFailureEvent(e)); // own, trivial event
}
}); Prevention
- Keep failure-event constructors side-effect free: store the Throwable, nothing else
- Use the built-in ThrowableFailureEvent unless you truly need a custom type
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failure event class must have a constructor with one paramet
- Unexpected exception
- Could not inspect methods of ${clazz.getName()}. Please make
- It looks like you are using EventBus on Android, make sure t
- Subscriber ${subscriber.getClass()} already registered to ev
AI-assisted analysis of greenrobot/EventBus@0194926b3b (2026-08-14).
Data as JSON: /api/errors/7ff7e288ba64eaf8.
Report an issue: GitHub.