NSWorkspace - macOS Tahoe 26.4 -activateFileViewerSelectingURLs: Crashes When Called Off The Main Thread

So I just installed the 26.4 update and unfortunately I have to debug this newly introduced issue (that may work its way into a separate thread).

In my debugging steps I'm testing something related to files and I used -activateFileViewerSelectingURLs: to show the file in Finder. Now I am off the main thread.

I added this line for testing purposes and I get a crash:

NSWindow should only be instantiated on the main thread!' terminating due to uncaught exception of type NSException.

So apparently - NSWorkspace is calling through to NSServices APIs and for some reason the system wants to present an NSError, which is a subtopic and other bug on its own because the 'Show in Finder" functionality actually WORKS but it crashed my app!

#22in +[NSAlert alertWithError:] ()

#23in -[NSApplication(NSErrorPresentation) presentError:] ()

#24 +[NSServicesMenuHandler _performServiceFromEntry:withPasteboard:withRequestor:withInvocationSourceType:withCarbonFocus:withSendTypes:withReturnTypes:canReleasePasteboardImmediately:] ()

#25 +[NSServicesMenuHandler _performServiceWithoutAlternatesFromEntry:withPasteboard:withRequestor:withInvocationSourceType:] ()

#26 +[NSServicesMenuHandler _performServiceFromEntry:withPasteboard:withRequestor:withInvocationSourceType:] ()

#27 [NSWorkspace activateFileViewerSelectingURLs:]

What error it is trying to present.. I have no idea. I'm not sure if I actually have a code path that calls this method off the main thread but I guess I'll have to check. This clearly goes against the documentation. NSWorkspace documentation clearly states:

-activateFileViewerSelectingURLs:

Discussion You can safely call this method from any thread of your app.

Is this new in 26.4? I'm not sure but I just noticed.

I definitely use other NSWorkspace methods off the main thread in areas of my app. Like -activateFileViewerSelectingURLs: the documentation for those other methods claims you can safely call them off the main thread. So now I'm concerned.

Answered by DTS Engineer in 881799022

Dear Macho Man Randy Savage,

This does look like a bug, thank you for investigating it and reporting FB22340592. For the time being, please try the workaround of calling activateFileViewerSelectingURLs: from the main thread only.

Best regards,

Richard Yeh  Developer Technical Support

I file FB 22340592

(space intentionally added because posting FB links seems to cause posts to be flagged until approved by a moderator, suddenly).

Dear Macho Man Randy Savage,

This does look like a bug, thank you for investigating it and reporting FB22340592. For the time being, please try the workaround of calling activateFileViewerSelectingURLs: from the main thread only.

Best regards,

Richard Yeh  Developer Technical Support

This might be an older bug. I experienced this years ago. In addition to using the main thread, I even moved this method call to an XPC service. And then later, I added another crash-happy API call to my service as well.

NSWorkspace - macOS Tahoe 26.4 -activateFileViewerSelectingURLs: Crashes When Called Off The Main Thread
 
 
Q