JDK-8092352 : Skip event dispatch if there are no handlers/filters
Type:Enhancement
Component:javafx
Sub-Component:scenegraph
Affected Version:8,openjfx13
Priority:P4
Status:Resolved
Resolution:Fixed
Submitted:2012-08-03
Updated:2019-10-01
Resolved:2019-10-01
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
EventHandlerManager's methods dispatchCapturingEvent and dispatchBubblingEvent have TODOs: skip when no filters/handlers are registered in the CompositeEventHandler.
Comments
Changeset: 1fb5d32ea90b
Author: fastegal
Date: 2019-10-01 05:11 -0700
URL: https://hg.openjdk.java.net/openjfx/jfx-dev/rt/rev/1fb5d32ea90b
8092352: Skip dispatch if there are no handlers/filters
Reviewed-by: kcr, arapte
01-10-2019
not quite as simple: the handler is the special one (registered via onXX?), rather independent of what resides in the EventProcessorRecords ;) Simply checking that special one for null results in several event dispatch tests failing.
Next try: let the CompositeEventHandler decide whether it has handlers/filters
public boolean hasAnyFilter() {
return findAny(true);
}
public boolean hasAnyHandler() {
if (getEventHandler() != null) return true;
return findAny(false);
}
and let EventHandlerManager use these to not dispatch if there's no filter/handler:
in dispatchCapturing:
// grab compositeEventHandler as in last comment
// dispatch only if there actually is a filter
if (hasFilter(compositeHandler)) {
event = //copied event
compositeHandler.dispatchCapturing ..
}
private boolean hasFilter(
final CompositeEventHandler<? extends Event> compositeEventHandler) {
return compositeEventHandler != null && compositeEventHandler.hasAnyFilter();
}
doing so lets the core tests pass, and alleviates JDK-8229467 in environments where all filters have been removed (obviously does not help if there _are_ filters, the action is still copied which makes checking its consumed state by the sender useless)
22-08-2019
Dispatching an event to a filter has the side-effect of copying the event: doing so for the sake of filters might be the correct thingy to do (I'm not familiar enough with the dispatch mechanism to judge), but if done even if there are no filters implies coying without any reason (which is part of breaking JDK-8229467)
Afaics, fixing this would be simple and has low risk: instead of checking only the compositeHandler against null also check its active handler against null, something like:
private Event dispatchCapturingEvent(
final EventType<? extends Event> handlerType, Event event) {
final CompositeEventHandler<? extends Event> compositeEventHandler =
eventHandlerMap.get(handlerType);
// current:
// if (compositeEventHandler != null) {
// change to:
if (compositeEventHandler != null && compositeHandler.getEventHandler() != null) {
// TODO: skip when no filters are registered in the
// CompositeEventHandler (RT-23952)
event = fixEventSource(event, eventSource);
compositeEventHandler.dispatchCapturingEvent(event);
}
return event;
}