Component.dispatchEvent ignores ActionEvents
ingebot opened this issue · comments
Note: this issue was migrated automatically using bugzilla2github
Original bug ID: BZ#70663
From: @guillerodriguez
Reported version: 0.99
Comment author: @guillerodriguez
The API specification for java.awt.Component.dispatchEvent() says: "Dispatches an event to this component or one of its sub components. Calls processEvent before returning for 1.1-style events which have been enabled for the Component."
According to this description, the attached sample code should output this:
Dispatching action event
processEvent called
This works as expected on OpenJDK. However in GNU Classpath thw result is:
Dispatching action event
i.e. the processEvent() method is never called.
This happens because the eventTypeEnabled() method in Classpath's implementation of Component does not know about action events and will always return false for them, even if they have been enabled.
This breaks lightweight components that generate action events by themselves.
Sample code follows.
import java.awt.*;
import java.awt.event.ActionEvent;
public class Sample extends Component
{
protected void processEvent(AWTEvent e)
{
System.out.println("processEvent called");
super.processEvent(e);
}
public void simulateActionEvent()
{
System.out.println("Dispatching action event");
enableEvents(AWTEvent.ACTION_EVENT_MASK);
ActionEvent ev = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "test");
dispatchEvent(ev);
}
public static void main(String args[])
{
Sample sample = new Sample();
sample.simulateActionEvent();
}
}
Comment author: @guillerodriguez
Created attachment 38268
Proposed fix
The attached patch fixes this behaviour.
Attached file: Component_dispatch_action_events.patch (text/plain, 303 bytes)
Description: Proposed fix