Bug 250255

Summary: LightweightSystem#setUpdateManager does't dispose old UpdateManager
Product: [Tools] GEF Reporter: Heiko Böttger <heiko.boettger>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Heiko Böttger CLA 2008-10-09 06:05:00 EDT
Build ID: M20080911-1700

Steps To Reproduce:
public class EditableFigureCanvasTest extends TestCase {
  private static final class TestUpdateManager extends UpdateManager {
    @Override
    public void addDirtyRegion(IFigure figure, int x, int y, int w, int h) {
      
    }

    @Override
    public void addInvalidFigure(IFigure figure) {
      
    }

    @Override
    public void performUpdate() {
      
    }

    @Override
    public void performUpdate(Rectangle exposed) {
      
    }

    @Override
    public void setGraphicsSource(GraphicsSource gs) {
      
    }

    @Override
    public void setRoot(IFigure figure) {
      
    }

    @Override
    public boolean isDisposed() {
      return super.isDisposed();
    }
  }

  @Test
  public void test_setUpdateManager() {
    //test if old updateManager is disposed
    Display.getDefault().syncExec(new Runnable() {
      public void run() {
        //test if bug still exists
        LightweightSystem lightweightSystem = new LightweightSystem();
        TestUpdateManager um = new TestUpdateManager();
        lightweightSystem.setUpdateManager(um);
        lightweightSystem.setUpdateManager(new TestUpdateManager());
        assertFalse("bug is fixed, remove workaround",um.isDisposed());
           }
    });
  }
}

To Produce a widget is disposed exception setup a canvas:
1. create a canvas
2. add an update listener to the UpdateManager
3. access the canvas inside listener
4. dispose canvas after replacing the UpdateManager


More information:
If the widget is disposed after setting the new UpdateManager, the old UpdateManager is not disposed and will execute its pending updates and validations. This will result in a widget is disposed error.