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

Bug 343318

Summary: sendToolTipEvent blows up with a null pointer exception when the window == null
Product: [Eclipse Project] Platform Reporter: Jeff Stano <jstano>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: critical    
Priority: P3 CC: lshanmug
Version: 3.6.2   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

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.