Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343318 - sendToolTipEvent blows up with a null pointer exception when the window == null
Summary: sendToolTipEvent blows up with a null pointer exception when the window == null
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.2   Edit
Hardware: Macintosh Mac OS X
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-19 17:53 EDT by Jeff Stano CLA
Modified: 2011-04-20 03:01 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Stano CLA 2011-04-19 17:53:57 EDT
Build Identifier: SWT-3.6.2 Cocoa Mac OSX 64

When creating a Shell using the SWT_AWT.new_Shell method, the created Shell has the window object set to null. This causes the sendToolTipEvent to blow up, since there is not a check for window == null. This only happens when creating a Shell that is embedded in a AWT/Swing application.

Here is the code for the sendToolTipEvent method


void sendToolTipEvent (boolean enter) {
	if (!isVisible()) return;
	if (tooltipTag == 0) {
		NSView view = window.contentView();
		tooltipTag = view.addToolTipRect(new NSRect(), window, 0);
		if (tooltipTag != 0) {
			NSTrackingArea trackingArea = new NSTrackingArea(tooltipTag);
			id owner = trackingArea.owner();
			if (owner != null) tooltipOwner = owner.id;
			id userInfo = trackingArea.userInfo();
			if (userInfo != null) {
				tooltipUserData = userInfo.id;
			} else {
				long /*int*/ [] value = new long /*int*/ [1];
				OS.object_getInstanceVariable(tooltipTag, new byte[]{'_','u', 's', 'e', 'r', 'I', 'n', 'f', 'o'}, value);
				tooltipUserData = value[0];
			}
		}
	}
	if (tooltipTag == 0 || tooltipOwner == 0 || tooltipUserData == 0) return;
	NSPoint pt = window.convertScreenToBase(NSEvent.mouseLocation());
	NSEvent event = NSEvent.enterExitEventWithType(enter ? OS.NSMouseEntered : OS.NSMouseExited, pt, 0, 0, window.windowNumber(), null, 0, tooltipTag, tooltipUserData);
	OS.objc_msgSend(tooltipOwner, enter ? OS.sel_mouseEntered_ : OS.sel_mouseExited_, event.id);
}

The problem starts with the code in windowSendEvent method in the Shell class. The line that causes the blowup is

				if (shell != null) shell.sendToolTipEvent (true);


Reproducible: Always

Steps to Reproduce:
1.Create a shell using SWT_AWT.new_Shell(display, canvas) where canvas is a valid java.awt.Canvas instance.
2.Create a new Shell in a second window.
3.
Comment 1 Lakshmi P Shanmugam CLA 2011-04-20 03:01:23 EDT
This got fixed in 3.7M3 (as part of fix for Bug 324345). This is the code in 3.7 HEAD, we are using view.window() instead of 'window':

NSWindow eventWindow = view.window();
if (tooltipTag == 0) {
    NSView view = eventWindow.contentView();

Closing bug, please reopen if problem is seen with recent 3.7 builds.