JDK-8015303 : [macosx] Application launched via custom URL Scheme does not receive URL
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,7u6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2013-05-22
  • Updated: 2014-11-17
  • Resolved: 2013-05-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u40Fixed 8 b94Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin cranky.local 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan  6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
A bundled mac application (using the Appbundler ant task https://java.net/projects/appbundler), which registers custom url schemes via the CFBundleURLSchemes entry in its Info.plist, and listens for uri events using com.apple.eawt.Application.setOpenURIHandler will not receive the URI used to launch the application.

Once the application is running however, subsequent openURI events will be received without issue, the problem only manifests when a url is used to launch the App initially.

According to the jdk mailing list, this issue may have already been reported by AJ Gregory in bug id 9000081, but this issue is not viewable:

http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-March/005432.html

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) In the Java application, use  com.apple.eawt.Application.setOpenURIHandler to register the openURI callback
2) Bundle the application with https://java.net/projects/appbundler
3) Register custom url schemes (e.g. 'foo:' )by adding entries to the bundle's Info.plist
4) Launch the bundled app by clicking a 'foo:bar' link in a browser, or type 'open foo:bar' in the terminal


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application's callback, registered with com.apple.eawt.Application.setOpenURIHandler, should be invoked with the 'foo:bar' url.
ACTUAL -
The openURIHandler callback method is not invoked

ERROR MESSAGES/STACK TRACES THAT OCCUR :
The mac console.app shows the following errors when the uri is used to launch the app:

5/20/13 4:10:06.169 PM JavaAppLauncher[74278]: -[NSAppleEventDescriptor paramDescriptorForKeyword:] called on invalid NSAppleEventDescriptor
5/20/13 4:10:06.171 PM JavaAppLauncher[74278]: (
     0   CoreFoundation                      0x00007fff8d09bb06 __exceptionPreprocess + 198
     1   libobjc.A.dylib                     0x00007fff913843f0 objc_exception_throw + 43
     2   CoreFoundation                      0x00007fff8d09b8dc +[NSException raise:format:] + 204
     3   Foundation                          0x00007fff8d72bd43 -[NSAppleEventDescriptor paramDescriptorForKeyword:] + 71
     4   liblwawt.dylib                      0x000000013cbaeb77 -[ApplicationDelegate _handleOpenURLEvent:withReplyEvent:] + 137
     5   libosxapp.dylib                     0x000000013c24e8b1 __-[QueuingApplicationDelegate _handleOpenURLEvent:withReplyEvent:]_block_invoke_1 + 135
     6   libosxapp.dylib                     0x000000013c24f7bf -[QueuingApplicationDelegate processQueuedEventsWithTargetDelegate:] + 134
     7   libosxapp.dylib                     0x000000013c24d857 OSXAPP_SetApplicationDelegate + 153
     8   liblwawt.dylib                      0x000000013cbad899 __+[AWTStarter start:swtMode:swtModeForWebStart:]_block_invoke_1 + 111
     9   JavaNativeFoundation                0x000000013b87e53d +[JNFRunLoop _performDirectBlock:] + 12
     10  Foundation                          0x00007fff8d75bd3a __NSThreadPerformPerform + 225
     11  CoreFoundation                      0x00007fff8d01ab31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
     12  CoreFoundation                      0x00007fff8d01a455 __CFRunLoopDoSources0 + 245
     13  CoreFoundation                      0x00007fff8d03d7f5 __CFRunLoopRun + 789
     14  CoreFoundation                      0x00007fff8d03d0e2 CFRunLoopRunSpecific + 290
     15  HIToolbox                           0x00007fff9602deb4 RunCurrentEventLoopInMode + 209
     16  HIToolbox                           0x00007fff9602db94 ReceiveNextEventCommon + 166
     17  HIToolbox                           0x00007fff9602dae3 BlockUntilNextEventMatchingListInMode + 62
     18  AppKit                              0x00007fff954f5563 _DPSNextEvent + 685
     19  AppKit                              0x00007fff954f4e22 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
     20  libosxapp.dylib                     0x000000013c24db56 -[NSApplicationAWT nextEventMatchingMask:untilDate:inMode:dequeue:] + 124
     21  AppKit                              0x00007fff954ec1d3 -[NSApplication run] + 517
     22  libosxapp.dylib                     0x000000013c24d9b9 +[NSApplicationAWT runAWTLoopWithApp:] + 156
     23  liblwawt.dylib                      0x000000013cbad81a -[AWTStarter starter:] + 1591
     24  Foundation                          0x00007fff8d75bd3a __NSThreadPerformPerform + 225
     25  CoreFoundation                      0x00007fff8d01ab31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
     26  CoreFoundation                      0x00007fff8d01a455 __CFRunLoopDoSources0 + 245
     27  CoreFoundation                      0x00007fff8d03d7f5 __CFRunLoopRun + 789
     28  CoreFoundation                      0x00007fff8d03d0e2 CFRunLoopRunSpecific + 290
     29  libjli.dylib                        0x000000010d6a688d CreateExecutionEnvironment + 871
     30  libjli.dylib                        0x000000010d6a103c JLI_Launch + 1952
     31  JavaAppLauncher                     0x000000010d60a8d3 launch + 7603
     32  JavaAppLauncher                     0x000000010d608906 main + 102
     33  JavaAppLauncher                     0x000000010d608894 start + 52
     34  ???                                 0x0000000000000002 0x0 + 2
)

It appears that the NSAppleEventDescriptor reference queued by the QueuingApplicationDelegate is invalidated by the time it is processed by the real ApplicationDelegate.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
The issue appears to be in jdk/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m (from the OpenJDK jdk7u repository).

The following patch resolves the issue:
-----------
diff -r fd2743154fcf src/macosx/native/sun/osxapp/QueuingApplicationDelegate.m
--- a/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.mWed May 08 16:52:22 2013 -0700
+++ b/src/macosx/native/sun/osxapp/QueuingApplicationDelegate.mWed May 22 12:41:08 2013 -0400
@@ -110,8 +110,14 @@
 
 - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent
 {
+    // Make an explicit copy of the passed events as they may be invalidated by the time they're processed
+    NSAppleEventDescriptor *openURLEventCopy = [openURLEvent copy];
+    NSAppleEventDescriptor *replyEventCopy = [replyEvent copy];
+
     [self.queue addObject:[^(){
-        [self.realDelegate _handleOpenURLEvent:openURLEvent withReplyEvent:replyEvent];
+        [self.realDelegate _handleOpenURLEvent:openURLEventCopy withReplyEvent:replyEventCopy];
+        [openURLEventCopy release];
+        [replyEventCopy release];
     } copy]];
 }
-----------
Comments
noreg-hard: testing this fix involves bundling a test application for MacOSX. If it's ultimately needed to manually test this fix, please read this email thread: http://mail.openjdk.java.net/pipermail/awt-dev/2013-May/004835.html
30-05-2013

both bugs came in via webbugs
23-05-2013

this may be a duplicate of JDK-8015302
23-05-2013