Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312528 - Missing AddRef in new Accessible(parent)
Summary: Missing AddRef in new Accessible(parent)
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.6 RC1   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-12 01:06 EDT by Carolyn MacLeod CLA
Modified: 2010-05-12 11:36 EDT (History)
1 user (show)

See Also:
Silenio_Quarti: review+


Attachments
patch containing print statements to show problem (1.08 KB, patch)
2010-05-12 01:06 EDT, Carolyn MacLeod CLA
no flags Details | Diff
this patch is the fix (no prints) (772 bytes, patch)
2010-05-12 01:09 EDT, Carolyn MacLeod CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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