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

Bug 336957

Summary: Crash in SWT Carbon OS.ReceiveNextEvent / Display.trayItemProc
Product: [Eclipse Project] Platform Reporter: Greg Smith <gregsmit>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED FIXED QA Contact: Lakshmi P Shanmugam <lshanmug>
Severity: normal    
Priority: P3 CC: kleind, mukund, skovatch
Version: 3.6.1   
Target Milestone: 3.7 M6   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Apple crash report showing the result of the crash
none
fix none

Description Greg Smith CLA 2011-02-11 11:16:01 EST
Build Identifier: 3.6.1.v3655c

We are sometimes getting crashes in the Carbon SWT at shutdown.

It is intermittent, and but does occur during the time that the application is shutting down, and the Display is being shutdown. 

I will attach the Apple Crash Report of when the event occurred.  Unfortunately, I can not recreate it at will.

It appears to be related to receiving another event, and the tray item.  The Java stack at the time of the crash is:

j org.eclipse.swt.widgets.Display.trayItemProc(IIII)I+4 
v ~StubRoutines::call_stub 
J org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(I[IDZ[I)I 
j org.eclipse.swt.widgets.Display.readAndDispatch()Z+46 
j org.eclipse.swt.widgets.Display.release()V+72 
j org.eclipse.swt.graphics.Device.dispose()V+50 
j com.ibm.rcp.personality.framework.internal.RCPApplication.run(Ljava/lang/ Object;)Ljava/lang/Object;+251 
v ~StubRoutines::call_stub j sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/ lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0 
j sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/ Object;)Ljava/lang/Object;+87 
j sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/ Object;)Ljava/lang/Object;+6 
j java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/ Object;+161


The native stack is quite deep into the Apple APIs, and will be in the attached report.


Reproducible: Couldn't Reproduce
Comment 1 Greg Smith CLA 2011-02-11 11:17:59 EST
Created attachment 188788 [details]
Apple crash report showing the result of the crash
Comment 2 Greg Smith CLA 2011-02-11 11:54:07 EST
Correction -- The crash is caused by selecting "Exit" on the tray item.  So the user selects Exit on the tray item, then as the app is shutting down, the crash occurs.
Comment 3 David Klein CLA 2011-03-01 14:35:48 EST
The version of SWT in the bug summary is wrong.  It should be 3.6.1.  Greg, can you change this?
Also, it seems this may be related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=324155
Comment 4 Greg Smith CLA 2011-03-01 15:08:28 EST
Fixed -- sorry about that, the form that calculates that value from the build on a new seems to always set that value wrong.  I have fixed it.
Comment 5 Silenio Quarti CLA 2011-03-02 12:48:24 EST
I have not been able to reproduce the crash with this snippet. Is this app similar to yours? Do you have more details to help reproduce it?


/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;
  
/*
 * Tooltip example snippet: create a balloon tooltip for a tray item
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 * 
 * @since 3.2
 */
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet225 {

public static void main(String[] args) {
	final Display display = new Display();
	final Shell shell = new Shell(display);
	Image image = null;
	final ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
	tip.setMessage("Here is a message for the user. When the message is too long it wraps. I should say something cool but nothing comes to my mind.");
	Tray tray = display.getSystemTray();
	if (tray != null) {
		TrayItem item = new TrayItem(tray, SWT.NONE);
		image = display.getSystemImage(SWT.ICON_INFORMATION);
		item.setImage(image);
		tip.setText("Notification from a tray item");
		item.setToolTip(tip);
		item.addListener(SWT.MenuDetect, new Listener() {
			public void handleEvent(Event event) {
				Menu m = new Menu(shell, SWT.POP_UP);
				MenuItem mi = new MenuItem(m, SWT.PUSH);
				mi.setText("Exit");
				mi.addListener(SWT.Selection, new Listener() {
					public void handleEvent(Event event) {
						display.dispose();
					}
				});
				m.setVisible(true);
			}
		});
	} else {
		tip.setText("Notification from anywhere");
		tip.setLocation(400, 400);
	}
	Button button = new Button (shell, SWT.PUSH);
	button.setText("Press for balloon tip");
	button.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event event) {
			tip.setVisible(true);
		}
	});
	button.pack();
	shell.setBounds(50, 50, 300, 200);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	if (image != null) image.dispose();
	display.dispose();
}
}
Comment 6 Greg Smith CLA 2011-03-04 16:21:11 EST
Hi Silenio,

Our application is much larger than that, obviously, but that might be able to recreate the same situation.

The crash is intermittent, and seems to be fairly rare, as we have only had it reported to us once (that I know of) in a large amount of testing.

We can not recreate it at will, so its likely that you would not be able to recreate it easily either.
Comment 7 Silenio Quarti CLA 2011-03-04 16:59:35 EST
I am able to reproduce a problem that could be related. Run the snippet, press and "hold" the left mouse button in the tray item, move the mouse down so that the menu appears and select the "Exit" menu item.  This exception is printed to the console:

Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to org.eclipse.swt.widgets.TrayItem
	at org.eclipse.swt.widgets.Display.trayItemProc(Display.java:4409)
	at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3279)
	at org.eclipse.swt.widgets.Display.release(Display.java:3354)
	at org.eclipse.swt.graphics.Device.dispose(Device.java:206)
	at org.eclipse.swt.snippets.Snippet225$1$1.handleEvent(Snippet225.java:48)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1669)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1693)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1678)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1421)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3731)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3299)
	at org.eclipse.swt.snippets.Snippet225.main(Snippet225.java:69)

The stack is the same. It is not a segmentation fault, but the JVM could crash as well since the user_data passed to trayItemProc is not a valid JNI reference. It has been deleted in TrayItem.releaseWidget(). I am going to assume this is the same problem you are seeing.  Could you try these steps?
Comment 8 Silenio Quarti CLA 2011-03-04 17:02:47 EST
Created attachment 190453 [details]
fix

This is the patch to fix the problem I described above.
Comment 9 Silenio Quarti CLA 2011-03-04 17:12:18 EST
I released this to HEAD.

The same patch applies properly in the 3.6.2 branch, but note that there changes in the native code, so the SWT libraries have to be recompiled.

Fixed > 20110304
Comment 10 Greg Smith CLA 2011-03-04 17:25:11 EST
Hi Silenio,

Yes -- I think that's it.  I can recreate the same stack trace in our application -- so it must be that crash itself just "sometimes" happens as you mention because of something in the JNI.

Thanks much for your help.


2011/03/04 17:22:34.536 SEVERE CLPDN0021E: Exception trace follows: ::class.method=com.ibm.rcp.personality.framework.internal.RCPApplication.run() ::thread=Thread-0 ::loggername=com.ibm.rcp.personality.framework.internal

	java.lang.ClassCastException: java.lang.Object cannot be cast to org.eclipse.swt.widgets.TrayItem
	at org.eclipse.swt.widgets.Display.trayItemProc(Display.java:4335)
	at org.eclipse.swt.internal.carbon.OS.ReceiveNextEvent(Native Method)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3220)
	at org.eclipse.swt.widgets.Display.release(Display.java:3295)
	at org.eclipse.swt.graphics.Device.dispose(Device.java:206)
	at com.ibm.rcp.personality.framework.internal.RCPApplication.run(RCPApplication.java:75)
	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.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
..........