I recently had a VERY strange problem with a Xojo app. The core of the problem involves the following code:
folderPath = SpecialFolder.UserLibrary.NativePath
folderPath = folderPath + "/Application Support/Mozilla/Extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/"
extFolder = new FolderItem(folderPath, FolderItem.PathTypeNative)
This code was wrapped in a try block, as I fully expected it to fail on some systems, due to the lack of any such folder. However, a recent build of my app began exhibiting a very strange behavior: it was throwing a NilObjectException here, despite the fact that the code was inside a try block!
Stranger, this only happened on some systems, and not on others, and I couldn’t get the code to behave the same way in the debugger when running on an affected system. In the debugger, the code ran normally, generating no NilObjectException.
It gets stranger… it turns out, putting a MsgBox statement between the second and third lines of that code, then building and opening the app, caused the problem to stop. Removing it caused it to happen again. The contents of the MsgBox turned out to be irrelevant. In fact, another test showed that a simple loop (for i = 1 to 99 … next) inserted between those two lines was sufficient to stop the problem from happening.
Finally, I replaced those three lines with the following:
extFolder = SpecialFolder.UserLibrary.Child("Application Support").Child("Mozilla").Child("Extensions").Child("{ec8030f7-c20a-464f-9b0e-13a3a9e97384}")
This code works perfectly on the affected machines, and the NilOjbectException that is generated when some component of this path doesn’t exist is caught appropriately.
Can anyone explain what might be going on here? I’m at a total loss, especially since I’ve been using that code since before September, and earlier versions of this app work fine on the affected Macs. Affected machines were running a variety of systems (10.9 and 10.10), and had a variety of hardware (different amounts of RAM, both spinning and SSD drives, iMacs, MacBook Pros and MacBook Airs, etc). I could not identify any common characteristic about these Macs that was different on unaffected machines.