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

Bug 312528

Summary: Missing AddRef in new Accessible(parent)
Product: [Eclipse Project] Platform Reporter: Carolyn MacLeod <carolynmacleod4>
Component: SWTAssignee: Carolyn MacLeod <carolynmacleod4>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Silenio_Quarti
Version: 3.6Flags: Silenio_Quarti: review+
Target Milestone: 3.6 RC1   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
patch containing print statements to show problem
none
this patch is the fix (no prints) none

Description Carolyn MacLeod CLA 2010-05-12 01:06:47 EDT
Created attachment 168082 [details]
patch containing print statements to show problem

When a lightweight Accessible is created, a reference needs to be counted right away in the constructor. This prevents the object from being prematurely released.

Steps to show problem:
1) apply the attached patch to Accessible.java (note that this patch is not the fix - this patch contains the commented-out fix, plus some prints that show the problem)
2) run the LightweightAccessible snippet, below
3) run inspect32.exe
4) hover the mouse over the center of the shell, then close the shell
5) look at the console. The child object was released too many times
   (you will see "release=-1")
6) now uncomment the "AddRef();" in the constructor:
   public Accessible(Accessible parent)
7) repeat steps 2 - 5, except that this time, the child object refCount only goes down to 0.

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.accessibility.*;

public class LightweightAccessible {
	
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		
		final Accessible parentAcc = shell.getAccessible();
		final Accessible childAcc = new Accessible(parentAcc);
		childAcc.addAccessibleListener(new AccessibleAdapter() {
			public void getName(AccessibleEvent e) {
				e.result = "I am a lightweight accessible object.";
			}
		});
		childAcc.addAccessibleControlListener(new AccessibleControlAdapter() {
			public void getChildAtPoint(AccessibleControlEvent e) {
				e.childID = ACC.CHILDID_SELF;
			}
		});
		parentAcc.addAccessibleControlListener(new AccessibleControlAdapter() {
			public void getChildCount(AccessibleControlEvent e) {
				e.detail = 1;
			}
			public void getChildAtPoint(AccessibleControlEvent e) {
				e.accessible = childAcc;
			}
		});
		
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}
Comment 1 Carolyn MacLeod CLA 2010-05-12 01:09:13 EDT
Created attachment 168083 [details]
this patch is the fix (no prints)
Comment 2 Carolyn MacLeod CLA 2010-05-12 11:36:39 EDT
Fixed > 20100512