Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 324497 - [Widgets] NullPointerException at org.eclipse.swt.widgets.Link.textView_clickOnLink_atIndex
Summary: [Widgets] NullPointerException at org.eclipse.swt.widgets.Link.textView_click...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Scott Kovatch CLA
QA Contact: Silenio Quarti CLA
URL:
Whiteboard:
Keywords:
: 338228 339774 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-09-03 17:35 EDT by Matt Barry CLA
Modified: 2011-03-12 13:21 EST (History)
5 users (show)

See Also:


Attachments
Patch (838 bytes, patch)
2010-09-07 16:42 EDT, Scott Kovatch CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Barry CLA 2010-09-03 17:35:04 EDT
Build Identifier: I20100608-0911

java.lang.NullPointerException
	at org.eclipse.swt.widgets.Link.textView_clickOnLink_atIndex(Link.java:117)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5216)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:220)
	at org.eclipse.swt.widgets.Widget.mouseDownSuper(Widget.java:1025)
	at org.eclipse.swt.widgets.Widget.mouseDown(Widget.java:1021)
	at org.eclipse.swt.widgets.Control.mouseDown(Control.java:2240)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:220)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:1943)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2008)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5040)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:4582)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:4659)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:115)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3274)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)


Reproducible: Sometimes

Steps to Reproduce:
Haven't been able to associate this with a particular activity, but happens occasionally.
Comment 1 Lakshmi P Shanmugam CLA 2010-09-07 09:30:44 EDT
Not sure how the offsets field is null.
Comment 2 Praveen CLA 2010-09-07 12:58:58 EDT
I guess the widget is disposed in the Selection event by the user. I have experienced such exception in the past.
The fix is to we should check for isDisposed() after we send the selectionEvent.
Comment 3 Scott Kovatch CLA 2010-09-07 16:36:01 EDT
(In reply to comment #2)
> I guess the widget is disposed in the Selection event by the user.

I think Praveen is right. Here's a test case. Run it and click on the link and you'll get the NPE in the description.

=======================
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PR324497 {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setSize(100,100);
		final Shell shell2 = new Shell(display);
		shell2.setSize(260, 260);
		GridLayout layout = new GridLayout(1, false);
		shell2.setLayout(layout);	

		Link link = new Link(shell2, SWT.LEFT);
		link.setText("This is a <a>link</a>.");
		link.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent event) {
				shell2.close();
				shell2.dispose();
			}
		});

		Label label = new Label(shell2, SWT.LEFT);
		label.setText("This is a label.");

		shell.open();
		shell2.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}

}
Comment 4 Scott Kovatch CLA 2010-09-07 16:42:22 EDT
Created attachment 178359 [details]
Patch

Fixed as Praveen suggested.
Comment 5 Scott Kovatch CLA 2010-09-07 16:44:28 EDT
Fixed > 20100907.
Comment 6 Scott Kovatch CLA 2011-02-25 19:43:18 EST
*** Bug 338228 has been marked as a duplicate of this bug. ***
Comment 7 Praveen CLA 2011-03-12 13:21:19 EST
*** Bug 339774 has been marked as a duplicate of this bug. ***