Hard crash for FolderItem.Child

Does anyone have an idea what might cause a hard crash when accessing a folderitem?

Thread 4 Crashed:
0 com.apple.CoreFoundation 0x000000018ee59cec CFRetain.cold.1 + 16
1 com.apple.CoreFoundation 0x000000018ec8df90 CFRetain + 232
2 com.apple.CoreServicesInternal 0x000000019133b53c _CreateByResolvingAliasFile(__CFAllocator const*, __CFURL const*, unsigned long, unsigned char*, __CFError**) + 72
3 com.apple.CoreServicesInternal 0x0000000191349288 ___URLCreateByResolvingAliasFile_block_invoke + 56
4 libsystem_trace.dylib 0x000000018e9abe70 _os_activity_initiate_impl + 64
5 com.apple.CoreServicesInternal 0x000000019133b4cc _URLCreateByResolvingAliasFile + 152
6 com.apple.Foundation 0x000000018fb2a084 -[NSURL(NSURL) initByResolvingAliasFileAtURL:options:error:] + 308
7 com.apple.Foundation 0x000000018fb29f30 +[NSURL(NSURL) URLByResolvingAliasFileAtURL:options:error:] + 60
8 com.xojo.XojoFramework 0x000000010399f500 FolderItemImpNSURL::FolderItemImpNSURL(NSURL*, bool) + 88
9 com.xojo.XojoFramework 0x00000001039a1594 FolderItemImpNSURL::GetChildByName(string, long) + 284
10 com.xojo.XojoFramework 0x0000000103afc69c 0x10395c000 + 1705628
11 com.mothsoftware.mailarchiverx 0x000000010037ebe0 FolderItem.Child%o%osb + 76
12 com.mothsoftware.mailarchiverx 0x0000000101732818 reportPrinter.getFile%o%oosb

ARM, Xojo 2021r2.1.

For once, the location is in the temp folder and not in Dropbox. The files have a random file name because it’s the first step when creating PDF files.

My brain is going. I already had that crash before:

But as far as I remember I wasn’t able to solve the problem.

Seems like its calling an alias file?

The macOS thinks that this file is an Alias and is treating it at such, but appears to be crashing when trying to resolve the alias. Are you expecting aliases in this folder?

If not, then use folderitem.child( name, false ) so you get the Alias file and not the resolved alias. If you are expecting Aliases (App Wrapper uses Aliases for all kinds of things), then you really need more information about this file as I would hazard a guess in that either Xojo is building the NSURL incorrectly (file name issues) or there is a fundamental issue with that file to which the OS can not handle.

To validate this, you’re going need a copy of the Alias file, and even then you may not be able to reproduce it on your system, but if you can, hopefully you can trap the error.

Like the last time there is no alias involved. I create all the files.

Private Function getFile(parentFolderItem as FolderItem, theName as string, doFolder as Boolean) As Folderitem
  
  'get a folderitem to be used for the print report
  
  theName = theName.Trim
  
  'dim theFileNo as integer
  dim theFolderitem as folderitem
  dim theFileNo as Integer
  
  if parentFolderItem = nil then
    'nothing to do
  elseif not doFolder or PDFStructure = 0 then
    theFolderitem = parentFolderItem.Child(theName + ".pdf")
    while theFolderitem <> nil and theFolderitem.exists
      theFileNo = theFileNo + 1
      theFolderitem = parentFolderItem.Child(theName + " " + str(theFileNo) + ".pdf")
    wend
    
  ElseIf doFolder then
    theFolderitem = parentFolderItem.Child(theName)
    while theFolderitem <> nil and theFolderitem.exists
      theFileNo = theFileNo + 1
      theFolderitem = parentFolderItem.Child(theName + " " + str(theFileNo))
    wend
  end if
  
  exception exc
    theException = new ErrorException(exc, currentMethodName)
    
  finally
    
    return theFolderitem
    
End Function

https://documentation.xojo.com/api/files/folderitem.html.Child

You can see the second parameter is default true. It may be some kind of bug. You can try to set it to false if you are sure it’s not an alias.