-
Enhancement
-
Resolution: Unresolved
-
P3
-
None
-
os_x
On macOS OpenJDK performs the following checks when launching Java applications:
1. Acquires the main bundle for the application via [NSBundle mainBundle].
2. Installs the handler for OpenURL events only if the bundle contains CFBundleURLTypes or undocumented EAWTOverride entries in the Info.plist.
These checks fail to work properly if Java application is launched as a subprocess, e.g. when CFBundleExecutable points to a shell script that eventually runs java -jar application.jar ...arguments. In this case [NSBundle mainBundle] returns the rudimentary bundle for the java executable, which does not inherit the CFBundleURLTypes of the bundle it has been originally launched from. This prevents the OpenURL event handler from being registered, even though the original bundle enclosing the JAR file and the shell launcher for it has CFBundleURLTypes entry in its Info.plist.
Creating macOS bundles for Java applications with custom launchers seems like a valid use case. For example, an application may be historically coupled with a shell launcher that does some preprocessing on the environment.
The proposed solution is to add an on-demand installation of the OpenURL event handler when the application asks for it, e.g. by calling Application.setOpenURIHandler(). This would not break the specification for the affected API, since the requirement of the application being bundled and containing CFBundleURLTypes in the Info.plist would still be valid: macOS will neither launch nor send OpenURL events to an application that does not declare such capabilities it the bundle.
References:
[1] How Cocoa Applications Handle Apple Events : https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-SW10
[2] Information Property List Key Reference : https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102207-TPXREF115
[3] Defining a custom URL scheme for your app : https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
1. Acquires the main bundle for the application via [NSBundle mainBundle].
2. Installs the handler for OpenURL events only if the bundle contains CFBundleURLTypes or undocumented EAWTOverride entries in the Info.plist.
These checks fail to work properly if Java application is launched as a subprocess, e.g. when CFBundleExecutable points to a shell script that eventually runs java -jar application.jar ...arguments. In this case [NSBundle mainBundle] returns the rudimentary bundle for the java executable, which does not inherit the CFBundleURLTypes of the bundle it has been originally launched from. This prevents the OpenURL event handler from being registered, even though the original bundle enclosing the JAR file and the shell launcher for it has CFBundleURLTypes entry in its Info.plist.
Creating macOS bundles for Java applications with custom launchers seems like a valid use case. For example, an application may be historically coupled with a shell launcher that does some preprocessing on the environment.
The proposed solution is to add an on-demand installation of the OpenURL event handler when the application asks for it, e.g. by calling Application.setOpenURIHandler(). This would not break the specification for the affected API, since the requirement of the application being bundled and containing CFBundleURLTypes in the Info.plist would still be valid: macOS will neither launch nor send OpenURL events to an application that does not declare such capabilities it the bundle.
References:
[1] How Cocoa Applications Handle Apple Events : https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-SW10
[2] Information Property List Key Reference : https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-102207-TPXREF115
[3] Defining a custom URL scheme for your app : https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app
- links to
-
Review(master) openjdk/jdk/25967