Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328043

Summary: ClassCastException in DisposeEvent
Product: [RT] RAP Reporter: Steffen Kriese <steffen.kriese>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.4   
Target Milestone: 1.4 M3   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 324443    

Description Steffen Kriese CLA 2010-10-18 10:43:26 EDT
A call to notifyListeners(SWT.Dispose, event) on any widget, results in a ClassCastException. To reproduce it, just add the following lines to a widget like Text:

final Event newEvent = new Event();
newEvent.widget = this;
newEvent.type = SWT.Dispose;
newEvent.display = getDisplay();
notifyListeners(SWT.Dispose, newEvent);

This bug can also be reproduced by using the Riena ExampleClient and then go to Playground => Playground => Combos => CompletionCombo. 

Widget.notfyListener() calls UntypedEventAdapter.notifyListeners( final int eventType, final Event event ) which checks if it is a DisposeEventType and then tries to create a new DisposeEvent(event). DisposeEvent has a single argument constructor of type object, but the super constructor in TypedEvent expects the first parameter to be a widget. This of course results in a ClassCastException, because we passed in a Event instead of a Widget.

In my opinion UntypedEventAdapter should pass the widget from the source event to the new created DisposeEvent like: 


...
case SWT.Dispose:
        typedEvent = new DisposeEvent( event.widget);
  ...
Comment 1 Ivan Furnadjiev CLA 2010-11-05 07:04:03 EDT
Added missing ctor DisposeEvent( Event ). Fixed in CVS HEAD.