Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 45895 - [browser] get NPE when calling browser api from within dispose listener
Summary: [browser] get NPE when calling browser api from within dispose listener
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M1   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-31 17:18 EST by Christophe Cornu CLA
Modified: 2005-08-05 12:14 EDT (History)
1 user (show)

See Also:


Attachments
patch (1.04 KB, patch)
2005-06-23 16:26 EDT, Grant Gayed CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Cornu CLA 2003-10-31 17:18:07 EST
Run following class. Close Browser.
NPE in getUrl because auto is null. checkWidget does not work because the 
Browser dispose gets called before the Composite gets executed.


import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.*;

public class Browser1 {
	public static void main(String[] argv) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		Browser browser = new Browser(shell, SWT.NONE);
		LogBrowser log = new LogBrowser(browser, true);
		
		shell.open();
		browser.setUrl("http://www.eclipse.org");
		
		while (!shell.isDisposed()) if (!display.readAndDispatch()) 
display.sleep();
	}
}

import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;

public class LogBrowser implements ControlListener, DisposeListener, 
FocusListener, HelpListener, KeyListener, LocationListener,
		MouseListener, MouseMoveListener, MouseTrackListener, 
PaintListener, TraverseListener, ProgressListener, StatusTextListener {
	
	Browser browser;
	static int staticCnt = 0;
	
	public LogBrowser(Browser browser, boolean allEvents) {
		this.browser = browser;
		if (allEvents) {
			browser.addControlListener(this);
			browser.addDisposeListener(this);
			browser.addFocusListener(this);
			browser.addHelpListener(this);
			browser.addKeyListener(this);
			browser.addMouseListener(this);
		
			browser.addMouseMoveListener(this);
			browser.addMouseTrackListener(this);
			browser.addPaintListener(this);
			browser.addTraverseListener(this);
		}

		/* Browser specific */
		browser.addLocationListener(this);
		browser.addProgressListener(this);
		browser.addStatusTextListener(this);
	}
	
	static void print(LogBrowser log, String msg) {
		String out = ""+staticCnt;
		out += " "+log.browser.handle;
		out += " "+msg;
		out += " getUrl <"+log.browser.getUrl();
		
		staticCnt++;
		System.out.println(out);
	}
	
	/* ControlListener */
	public void controlMoved(ControlEvent e) {
		print(this, "controlMoved");
	}
	public void controlResized(ControlEvent e) {
		print(this, "controlResized");
	}

	/* DisposeListener */
	public void widgetDisposed(DisposeEvent e) {
		print(this, "widgetDisposed");
	}
	
	/* FocusListener */
	public void focusGained(FocusEvent e) {
		print(this, "focusGained");
	}
	
	public void focusLost(FocusEvent e) {
		print(this, "focusLost");
	}
	
	/* HelpListener */
	public void helpRequested(HelpEvent e) {
		print(this, "helpRequested");
	}
	
	/* KeyListener */
	public void keyPressed(KeyEvent e) {
		print(this, "keyPressed");
	}

	public void keyReleased(KeyEvent e) {
		print(this, "keyReleased");
	}
	
	/* MouseListener */
	public void mouseDoubleClick(MouseEvent e) {
		print(this, "mouseDoubleClick");
	}

	public void mouseDown(MouseEvent e) {
		print(this, "mouseDown");
	}

	public void mouseUp(MouseEvent e) {
		print(this, "mouseUp");
	}
	
	/* MouseMoveListener */
	public void mouseMove(MouseEvent e) {
		print(this, "mouseMove");
	}
	
	/* MouseTrackListener */
	public void mouseEnter(MouseEvent e) {
		print(this, "mouseEnter");
	}

	public void mouseExit(MouseEvent e) {
		print(this, "mouseExit");
	}

	public void mouseHover(MouseEvent e) {
		print(this, "mouseHover");
	}
	
	/* PaintListener */
	public void paintControl(PaintEvent e) {
		print(this, "paintControl");
	}
	
	/* TraverseListener */
	public void keyTraversed(TraverseEvent e) {
		print(this, "keyTraversed");
	}
	
	/** Browser specific **/
	
	/* LocationListener */
	public void changing(LocationEvent event) {
		print(this, "Location changing");
	}
	
	public void changed(LocationEvent event) {
		print(this, "Location changed");
	}
	
	/* ProgressListener */
	public void changed(ProgressEvent event) {
		print(this, "Progress changed");
	}
	
	public void completed(ProgressEvent event) {
		print(this, "Progress completed");
	}
	
	/* StatusTextListener */
	public void changed(StatusTextEvent event) {
		print(this, "StatusText changed");
	}
	
}
Comment 1 Grant Gayed CLA 2005-06-23 16:26:17 EDT
Created attachment 23894 [details]
patch
Comment 2 Grant Gayed CLA 2005-06-28 14:37:17 EDT
fixed > 0628