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

Bug 552063

Summary: [10.15] RCP app menu not active launching from Eclipse
Product: [Eclipse Project] Platform Reporter: Phil Beauvoir <p.beauvoir>
Component: SWTAssignee: Alex Blewitt <alex.blewitt>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: a.nesheret, alex.blewitt, alexandr.miloslavskiy, deboer, hubert+eclipseorg, lshanmug, ma.becker
Version: 4.13   
Target Milestone: 4.19 M2   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/174952
https://bugs.eclipse.org/bugs/show_bug.cgi?id=570428
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=e323e5d89a1d1413968d3b1160e632e77227fd72
Whiteboard:
Bug Depends on:    
Bug Blocks: 560902, 570428    

Description Phil Beauvoir CLA 2019-10-13 06:20:00 EDT
Eclipse Version: 2019-09 (4.13)
Eclipse Build id: I20190916-1045

MacOS 10.15 Catalina

1. New Plug-in Project
2. "Rich Client Application", Yes
3. Choose "RCP 3.x application with an intro"
4. Create a Launch/Run configuration and run this RCP app from Eclipse
5. Let the RCP app launch and wait until its splash screen finishes
6. Try to click on the app's menu items ("java", "File", "Help").
7. The menu items are not clickable until the app loses and regains focus.


This seems to be 10.15 specific and may happen only if the launched RCP app has a splash screen.

Might be related to Bug #426062
Comment 1 Lakshmi P Shanmugam CLA 2019-11-26 01:30:04 EST
I can see this problem when launching child eclipse with Java 11 and Java 13.
Doesn't happen if child eclipse is launched with Java 8.
Comment 2 Lakshmi P Shanmugam CLA 2019-11-26 01:59:18 EST
The problem also happens with standalone SWT applications.

@Till,
This bug is similar to Bug 457921 and Bug 426062 which happened with OSX 10.9 and was fixed with replacing the deprecated Cocoa APIs in SWT and Launcher code.
Any ideas on what could have changed in Mac 10.15 to break this again?
Comment 3 Till Brychcy CLA 2019-12-05 09:44:05 EST
(In reply to Lakshmi Shanmugam from comment #2)
> The problem also happens with standalone SWT applications.
> 
> @Till,
> This bug is similar to Bug 457921 and Bug 426062 which happened with OSX
> 10.9 and was fixed with replacing the deprecated Cocoa APIs in SWT and
> Launcher code.
> Any ideas on what could have changed in Mac 10.15 to break this again?

Sorry for not replying earlier, only just saw this.
I agree, probably new API behavior is being triggered by newer java (also observable in bug 553366)
Unfortunately I cannot examine this as I'm staying on 10.14 (as 10.15 doesn't support 32-bit apps anymore).
Comment 4 Phil Beauvoir CLA 2019-12-05 09:57:26 EST
Forgot to mention - this is with OpenJDK 11
Comment 5 Lakshmi P Shanmugam CLA 2019-12-09 06:15:59 EST
(In reply to Till Brychcy from comment #3)
> (In reply to Lakshmi Shanmugam from comment #2)
> > The problem also happens with standalone SWT applications.
> > 
> > @Till,
> > This bug is similar to Bug 457921 and Bug 426062 which happened with OSX
> > 10.9 and was fixed with replacing the deprecated Cocoa APIs in SWT and
> > Launcher code.
> > Any ideas on what could have changed in Mac 10.15 to break this again?
> 
> Sorry for not replying earlier, only just saw this.
> I agree, probably new API behavior is being triggered by newer java (also
> observable in bug 553366)
> Unfortunately I cannot examine this as I'm staying on 10.14 (as 10.15
> doesn't support 32-bit apps anymore).

@Till,
Not sure if it's Java related, as it happens with both Java 11 and Java 13 on macOS 10.15. So can the new API behaviour is triggered for some other reason?
Do you have a link to the AppKit changes in macOS 10.15? I can only find the release notes - https://developer.apple.com/documentation/macos_release_notes/macos_catalina_10_15_release_notes?language=objc
Comment 6 Till Brychcy CLA 2019-12-10 14:58:52 EST
(In reply to Lakshmi Shanmugam from comment #5)
> 
> @Till,
> Not sure if it's Java related, as it happens with both Java 11 and Java 13
> on macOS 10.15. So can the new API behaviour is triggered for some other
> reason?
> Do you have a link to the AppKit changes in macOS 10.15? I can only find the
> release notes -
> https://developer.apple.com/documentation/macos_release_notes/
> macos_catalina_10_15_release_notes?language=objc

I'm not aware of any AppKit specific release notes for 10.15.

In the other bug you wrote that java 12 and java 13 are linked against sdk 10.12, what about java 11?
It doesn't have to be that the API is changed in 10.15, but maybe the conditions when API changes from some previous sdk are activated have changed (which would probably be a macOS bug...)
Comment 7 Lakshmi P Shanmugam CLA 2019-12-11 23:58:51 EST
(In reply to Till Brychcy from comment #6)
> (In reply to Lakshmi Shanmugam from comment #5)
> > 
> > @Till,
> > Not sure if it's Java related, as it happens with both Java 11 and Java 13
> > on macOS 10.15. So can the new API behaviour is triggered for some other
> > reason?
> > Do you have a link to the AppKit changes in macOS 10.15? I can only find the
> > release notes -
> > https://developer.apple.com/documentation/macos_release_notes/
> > macos_catalina_10_15_release_notes?language=objc
> 
> I'm not aware of any AppKit specific release notes for 10.15.
> 
> In the other bug you wrote that java 12 and java 13 are linked against sdk
> 10.12, what about java 11?
Java 11 seems to be linked with SDK 10.10.
Comment 8 Till Brychcy CLA 2019-12-12 02:47:56 EST
(In reply to Lakshmi Shanmugam from comment #7)
> Java 11 seems to be linked with SDK 10.10.

Hmm, I'm back on my work-Macbook (also with 10.14) where I have a OpenJDK 11 installed, but it is linked against SDK 10.13:

% ./Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java -version

openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

% otool -l Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java | grep sdk

      sdk 10.13
Comment 9 Lakshmi P Shanmugam CLA 2019-12-12 03:14:35 EST
(In reply to Till Brychcy from comment #8)
> (In reply to Lakshmi Shanmugam from comment #7)
> > Java 11 seems to be linked with SDK 10.10.
> 
> Hmm, I'm back on my work-Macbook (also with 10.14) where I have a OpenJDK 11
> installed, but it is linked against SDK 10.13:
> 
> % ./Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java
> -version
> 
> openjdk version "11" 2018-09-25
> OpenJDK Runtime Environment 18.9 (build 11+28)
> OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
> 
> % otool -l
> Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/bin/java | grep sdk
> 
>       sdk 10.13

This is strange, I ran the same commands but sdk is 10.10 for me.

$ /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)

$ otool -l /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java | grep sdk
      sdk 10.10

I installed Java 11 from https://adoptopenjdk.net/?variant=openjdk11&jvmVariant=hotspot
Comment 10 Till Brychcy CLA 2019-12-12 04:18:48 EST
That explains the difference (and it is interesting that there is one), i have oracle's openjdk binaries from https://jdk.java.net/

But you wrote that you can observe the problem with your sdk 10.10-linked adoptopenjdk 11 binaries, right? And IIRC, the eclipse launcher is linked with 10.10, too, so it must be something different? (BTW: the java 8 binaries i have installed are all linked against sdk 10.8)
Comment 11 Lakshmi P Shanmugam CLA 2019-12-12 05:45:47 EST
(In reply to Till Brychcy from comment #10)
> That explains the difference (and it is interesting that there is one), i
> have oracle's openjdk binaries from https://jdk.java.net/
> 
> But you wrote that you can observe the problem with your sdk 10.10-linked
> adoptopenjdk 11 binaries, right? 
> And IIRC, the eclipse launcher is linked
> with 10.10, too, so it must be something different? (BTW: the java 8
> binaries i have installed are all linked against sdk 10.8)
That's right, problem happens with child eclipse launched with adoptopenjdk-11 but not with Eclipse launcher which is also linked with 10.10. As you said, looks like a different problem triggered only on 10.15.

Also found a similar issue logged in openjdk bug system - https://bugs.openjdk.java.net/browse/JDK-8233678
Comment 12 Lakshmi P Shanmugam CLA 2020-04-28 00:48:09 EDT
*** Bug 562535 has been marked as a duplicate of this bug. ***
Comment 13 Lakshmi P Shanmugam CLA 2020-04-28 00:50:20 EDT
Sample snippet and possible workaround to try in Bug 562535.
Comment 14 Phil Beauvoir CLA 2020-05-09 06:32:29 EDT
When debugging and running our RCP app from Eclipse on Mac 10.15 I click on the desktop and back to the app to get the main menu to work. But as a workaround, is there an equivalent to this in SWT that could be invoked in code just after the app launches?

Something like:

Shell shell = ...;
shell.loseFocus();
shell.getFocus();
Comment 15 Alex Blewitt CLA 2020-07-04 12:30:15 EDT
The bug still exists with recent versions of Eclipse (e.g. 2020-06) but seems to be reproducible on standalone Objective-C examples. It may be different behaviour depending on what the version of the SDK linked against is.

I've taken the sample code from the dupe'd bug report and packaged it up into a simple repro, which might help us identify or get the issue fixed.

https://github.com/alblue/Bugger
Comment 16 Alex Blewitt CLA 2020-07-05 08:25:42 EDT
This is a minimal reproducer with SWT/Cocoa:

--- 8< ---
import org.eclipse.swt.internal.cocoa.NSApplication;
import org.eclipse.swt.internal.cocoa.OS;

@SuppressWarnings("restriction")
public class Main {
	static long run = OS.sel_registerName("run");;

	public static void main(String[] args) {
		NSApplication app = NSApplication.sharedApplication();
		app.setActivationPolicy(OS.NSApplicationActivationPolicyRegular);
		app.activateIgnoringOtherApps(true);
		OS.objc_msgSend(app.id, run);
	}
}
--- 8< ---

I've also distilled it to a GitHub repo in Swift, which might help those in Apple
https://github.com/alblue/Bugger/blob/minimal/MinimalBug/main.swift

and a stackoverflow question:

https://stackoverflow.com/questions/62739862/why-doesnt-activateignoringotherapps-enable-the-menu-bar

The issue is that it seems to be a macOS related issue. I'll see if I can find out when it started.
Comment 17 Tim deBoer CLA 2020-12-21 23:39:28 EST
FWIW, I've been seeing this for the past year in my own apps and assumed it was my code, finally got around to trying to reproduce on something simpler and both saw it wasn't me and found this bug. I've seen this from <4.14/ Catalina/Java 8 to 4.18/Big Sur/Java 11.
Comment 18 Alex Blewitt CLA 2021-01-17 12:42:30 EST
I've found a fix for this; by moving the call to activateApps to the applicationDidFinishLanuching callback, the proper behaviour is restored.

There's a minimal test case fix at https://github.com/alblue/Bugger/commit/def736d6eb46df395ab8313a8d84446b0344b71c for the demo, will try and provide a patch to Eclipse that does the same thing.
Comment 19 Eclipse Genie CLA 2021-01-17 12:57:52 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/174952
Comment 20 Alex Blewitt CLA 2021-01-17 13:28:50 EST
NB the fix as proposed works when there's -nosplash passed on the command line. However, if the splash screen is shown there's the same issue. Bug 570428 can be used to track the fix in the eclipseCocoa.c launcher in Equinox.
Comment 22 Alex Blewitt CLA 2021-01-25 04:57:25 EST
Tested this fix with Build id: I20210124-1800 and verified it works when -nosplash is enabled.

With the splash screen shown this issue continues; will move investigation to the Eclipse launcher instead.
Comment 23 Phil Beauvoir CLA 2021-01-25 06:44:53 EST
Thanks for your work on this Alex.

I tested launching our RCP application against target I20210124-1800 on Big Sur 11.1 and can confirm that your fix works if -nosplash is enabled.

This will be a great help when launching our RCP app when working on a Mac. :-)
Comment 24 Alex Blewitt CLA 2021-02-12 09:02:31 EST
Verified fixed in I20210211-1810