OutOfBoundsException after build

Xojo 2017r3, MacOS X Mojave 10.14.4

My app opens a preferences file and reads in a string. Works great in the debugger, but when I build the application and run it I get an OutOfBounds Exception and the app quits. I’ve isolated this to the code that opens my preferences file, in the App.Open Event Handler (or in this case, in the MainWindow.Open event, since I tried moving it out of App.Open just for testing purposes - same error either way):

[code]//populate the preferences menu
dim prefsFilePath as string = SpecialFolder.ApplicationData.ShellPath + kSysDelim + App.ExecutableFile.Name + kSysDelim +“preferences.txt”
dim pFile as FolderItem = GetFolderItem(prefsFilePath,1)
dim prefsFileData as string

If pFile.Exists Then
Dim t As TextInputStream
Try
t = TextInputStream.Open(pFile)
t.Encoding = Encodings.UTF8
prefsFileData = t.ReadAll
t.Close
Catch e As IOException
MsgBox("Unable to open " + pFile.Name + ": " + e.Message)
End Try
End If
[/code]

It doesn’t display the error in my try/catch, so I don’t think it’s that it can’t find the file. It’s being handled by the App.UnhandledExceptions event handler. The preferences.txt file already exists at that location. And this the exception I’m getting:

RaiseOutOfBoundsException XojoFramework$12945 MainWindow.MainWindow.Event_Open%%o<MainWindow.MainWindow> FireWindowOpenEvents Window.Constructor%%o<Window> MainWindow.MainWindow%o<MainWindow.MainWindow>% App.Event_Open%%o<App> _Z29CocoaFinishApplicationStartupv XojoFramework$4427 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ___CFXRegistrationPost_block_invoke _CFXRegistrationPost ___CFXNotificationPost_block_invoke -[_CFXNotificationRegistrar find:object:observer:enumerator:] _CFXNotificationPost -[NSNotificationCenter postNotificationName:object:userInfo:] -[NSApplication _postDidFinishNotification] -[NSApplication _sendFinishLaunchingNotification] _DPSNextEvent -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] XojoFramework$4487 XojoFramework$4488 Application._CallFunctionWithExceptionHandling%%o<Application>p _Z33CallFunctionWithExceptionHandlingPFvvE XojoFramework$4487 -[NSApplication run] RuntimeRun REALbasic._RuntimeRun _Main main start

Any ideas?

@Perry Paolantonio — Is your application sandboxed?

dim prefsFilePath as string = SpecialFolder.ApplicationData.ShellPath + kSysDelim + App.ExecutableFile.Name + kSysDelim +"preferences.txt" dim pFile as FolderItem = GetFolderItem(prefsFilePath,1)

In this case, you should use NativePath (which equals 3) instead of ShellPath, because you do not make sure that the string you add (i.e. App.ExecutableFile.Name) is properly escaped.

To be honest - I have no idea. How would I tell? A setting in the IDE somewhere?

You don’t sell in the AppStore, don’t you? Then it’s likely that the app isn’t sandboxed.

Please don’t do something like that:

dim prefsFilePath as string = SpecialFolder.ApplicationData.ShellPath + kSysDelim + App.ExecutableFile.Name + kSysDelim +"preferences.txt" dim pFile as FolderItem = GetFolderItem(prefsFilePath,1)

Use instead:

dim pFile as folderitem = SpecialFolder.ApplicationData if pFile = nil or not pFile.exists then msgbox "bloody Apple" return end if 'and so on

You don’t have an OutOfBoundsException in your code but in Xojo. So you need to remove your code until the OOBE goes away.

I do not - the apps I’m building are strictly for in-house use.

[quote=459668:@Beatrix Willius]
Use instead:

dim pFile as folderitem = SpecialFolder.ApplicationData if pFile = nil or not pFile.exists then msgbox "bloody Apple" return end if 'and so on

You don’t have an OutOfBoundsException in your code but in Xojo. So you need to remove your code until the OOBE goes away.[/quote]

Other than style, I don’t see how your code is technically any different than what I’m doing (other than also testing if the file is nil) - what am I missing? – also in your code, we’re just looking at the ApplicationData folder, not the /preferences.txt file, which is all I’m interested in here.

Ok, I deleted the ApplicationSupport/ folder, added a test for whether pfile is nil, and now it’s working. The thing I don’t understand is why it didn’t work before - the folder was there from a previous build, so why wasn’t it being read?