greenrobot/EventBus · error · EventBusException
Only the currently handled event may be aborted
Error message
Only the currently handled event may be aborted
What it means
Thrown by cancelEventDelivery(Object) when postingState.event != event — a reference-identity comparison against the event currently being dispatched on this thread. Cancellation can only abort the one event whose delivery loop is on the thread's PostingThreadState stack; passing a different instance (even an equal() one, e.g. a reconstructed copy or another event of the same class) is rejected because cancelling it would corrupt unrelated dispatch state.
Source
Thrown at EventBus/src/org/greenrobot/eventbus/EventBus.java:299
}
}
/**
* Called from a subscriber's event handling method, further event delivery will be canceled. Subsequent
* subscribers
* won't receive the event. Events are usually canceled by higher priority subscribers (see
* {@link Subscribe#priority()}). Canceling is restricted to event handling methods running in posting thread
* {@link ThreadMode#POSTING}.
*/
public void cancelEventDelivery(Object event) {
PostingThreadState postingState = currentPostingThreadState.get();
if (!postingState.isPosting) {
throw new EventBusException(
"This method may only be called from inside event handling methods on the posting thread");
} else if (event == null) {
throw new EventBusException("Event may not be null");
} else if (postingState.event != event) {
throw new EventBusException("Only the currently handled event may be aborted");
} else if (postingState.subscription.subscriberMethod.threadMode != ThreadMode.POSTING) {
throw new EventBusException(" event handlers may only abort the incoming event");
}
postingState.canceled = true;
}
/**
* Posts the given event to the event bus and holds on to the event (because it is sticky). The most recent sticky
* event of an event's type is kept in memory for future access by subscribers using {@link Subscribe#sticky()}.
*/
public void postSticky(Object event) {
synchronized (stickyEvents) {
stickyEvents.put(event.getClass(), event);
}
// Should be posted after it is putted, in case the subscriber wants to remove immediately
post(event);
}View on GitHub (pinned to 0194926b3b)
Solutions
- Always forward the exact instance from the subscriber method parameter to cancelEventDelivery(event)
- Do not attempt to cancel past events — cancellation only affects subscribers that have not yet received the current event
- If you need type-based suppression, unsubscribe or filter at post() time instead
Example fix
// before
EventBus.getDefault().cancelEventDelivery(new MessageEvent(id)); // new instance -> throws
// after
@Subscribe(threadMode = ThreadMode.POSTING, priority = 100)
public void onEvent(MessageEvent event) {
EventBus.getDefault().cancelEventDelivery(event); // same instance being dispatched
} Defensive patterns
Strategy: validation
Validate before calling
// cancel must use the exact instance handed to the subscriber
@Subscribe(threadMode = ThreadMode.POSTING)
public void onEvent(MessageEvent event) {
EventBus.getDefault().cancelEventDelivery(event); // same reference, never a copy
} Prevention
- Never construct a new event instance for cancellation
- Remember comparison is by identity (==), not equals()
When it happens
Trigger: Constructing a new event instance (new MessageEvent(...)) and passing it to cancelEventDelivery instead of the instance received in the subscriber method; keeping the last event in a field and cancelling a previously delivered one; calling cancel for event B from inside the handler for event A.
Common situations: Developers assuming cancelEventDelivery works by event type or equality rather than instance identity; caching events and trying to retroactively cancel an already-delivered event.
Related errors
- Event may not be null
- This method may only be called from inside event handling me
- event handlers may only abort the incoming event
- @Subscribe method ${methodName}must have exactly 1 parameter
- ${methodName} is a illegal @Subscribe method: must be public
AI-assisted analysis of greenrobot/EventBus@0194926b3b (2026-08-14).
Data as JSON: /api/errors/6e292bfe37be86b3.
Report an issue: GitHub.