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

Bug 477979

Summary: [10.11] SWT can't receive input on non-standard JVMs
Product: [Eclipse Project] Platform Reporter: Joshua Warner <allpowerful32>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: keith, lshanmug, mtpersson
Version: 4.6   
Target Milestone: 4.6 M4   
Hardware: PC   
OS: Mac OS X   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543773
Whiteboard:
Bug Depends on:    
Bug Blocks: 482454    
Attachments:
Description Flags
patch none

Description Joshua Warner CLA 2015-09-21 12:59:29 EDT
Scenario:

* Any SWT-based app
* Works fine on < OSX 10.11
* Works fine on OSX 10.11, when running through standard (oracle/openjdk) Java install
* Breaks on OSX 10.11, when running through non-standard JVM (Avian, oss.readytalk.com/avian, in this case).  This is not an Avian-specific issue.

Expected: App renders correctly, and responds to input.

Actual: App renders correctly, but never responds to any input, including menus, window close button.  Appears frozen, except animations continue to render fine.

We tracked the problem down to where NSApplication.nextEventMatchingMask is being called with a mask of 0.  It looks like previously, this had the (undocumented) behavior of behaving like an "all events" mask.  Presumably, this was updated in OSX 10.11 to mean "no events".  Our theory is that Apple realized this broke some Java/SWT apps and decided to revert to the old behavior when the process name is "java", or some other sillyness.

The patch that works for us is as follows.  There's a similar usage in Tracker.java, but we don't happen to use that, and thus can't easily test that.

-------------
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
index ed7aefc..855fd76 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java
@@ -3689,7 +3689,7 @@ public boolean readAndDispatch () {
 		events |= runTimers ();
 		events |= runContexts ();
 		events |= runPopups ();
-		NSEvent event = application.nextEventMatchingMask(0, null, OS.NSDefaultRunLoopMode, true);
+		NSEvent event = application.nextEventMatchingMask(0xffffffffffffffffL, null, OS.NSDefaultRunLoopMode, true);
 		if (event != null) {
 			events = true;
 			application.sendEvent(event);
-------------
Comment 1 Lakshmi P Shanmugam CLA 2015-10-09 07:58:09 EDT
Sorry, I don't have Avian JVM to verify the problem or the fix. Will you be able to verify the fix in a Nightly build, when it's committed?
Also, can you please sign the CLA? (https://eclipse.org/legal/clafaq.php)
Comment 2 Joshua Warner CLA 2015-10-09 10:30:25 EDT
CLA Signed.  Although, I would humbly suggest it's a little silly to squabble over copyright assignment on such a tiny patch.

Yes, I'll be able to verify the fix.  FWIW, we've been running in production for a while now with the patched version of SWT.  We've found no further issues.

I'm also happy to help you build avian+swt+(an example app), should you want to verify the problem and solution yourself.
Comment 3 Lakshmi P Shanmugam CLA 2015-10-12 03:05:30 EDT
(In reply to Joshua Warner from comment #2)
> CLA Signed.  Although, I would humbly suggest it's a little silly to
> squabble over copyright assignment on such a tiny patch.
Thanks! I don't see any squabble here.
It is part of the eclipse process where we ask the contributor to sign the CLA when submitting a contribution for the first time. You don't have to do it with every contribution. 
The CLA of the author is automatically checked when a patch is submitted to source control system (git) or gerrit review. If the CLA is not signed the commit is rejected.
Comment 4 Lakshmi P Shanmugam CLA 2015-10-14 02:17:47 EDT
Created attachment 257249 [details]
patch

Hi Joshua,
This patch is based on your suggested changes. I've also made the same change in the Tracker class. Please test the patch in your setup.
Also, can you verify if Tracker has the same problem and the patch fixes it?

(Example snippets for Tracker - http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet31.java and 
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet23.java)

Thanks.
Comment 5 Joshua Warner CLA 2015-10-19 12:32:06 EDT
Sorry for the delay.  Confirmed; that patch fixes both issues (the general interaction and Tracker example) on avian + El Capitan.  Thanks for the pointer on the Tracker example - that sped things up substantially!
Comment 6 Lakshmi P Shanmugam CLA 2015-10-26 05:02:39 EDT
(In reply to Joshua Warner from comment #5)
> Sorry for the delay.  Confirmed; that patch fixes both issues (the general
> interaction and Tracker example) on avian + El Capitan.  Thanks for the
> pointer on the Tracker example - that sped things up substantially!

Thanks for testing the patch. Will commit post M3.
Comment 8 Lakshmi P Shanmugam CLA 2015-11-05 00:13:16 EST
Hi Joshua,
Can you please verify the fix in the nightly build? Thanks!
-->http://download.eclipse.org/eclipse/downloads/drops4/N20151104-2000/download.php?dropFile=eclipse-SDK-N20151104-2000-macosx-cocoa-x86_64.tar.gz
Comment 9 Lakshmi P Shanmugam CLA 2015-11-20 00:27:37 EST
(In reply to Lakshmi Shanmugam from comment #8)
> Hi Joshua,
> Can you please verify the fix in the nightly build? Thanks!
> -->http://download.eclipse.org/eclipse/downloads/drops4/N20151104-2000/
> download.php?dropFile=eclipse-SDK-N20151104-2000-macosx-cocoa-x86_64.tar.gz

The above N-build is no longer available, please verify in the latest I-build -- http://download.eclipse.org/eclipse/downloads/drops4/I20151117-0800/download.php?dropFile=eclipse-SDK-I20151117-0800-macosx-cocoa-x86_64.tar.gz
Comment 10 Lakshmi P Shanmugam CLA 2015-12-08 06:36:13 EST
Ping. 
This fix will be part of the 4.6M4 milestone build. Can you please verify it on a I-build (http://download.eclipse.org/eclipse/downloads/drops4/I20151207-2000/download.php?dropFile=eclipse-SDK-I20151207-2000-macosx-cocoa-x86_64.tar.gz)
Thanks!
Comment 11 Markus Persson CLA 2016-08-19 10:44:52 EDT
For the record, I just want to add that this bug is most likely also the cause of bug 472259. It is just that Apple provided a workaround so that most Eclipse users are guarded from it.
Comment 12 Dani Megert CLA 2018-02-07 09:31:22 EST
*** Bug 530267 has been marked as a duplicate of this bug. ***