NilObjectException in FileListMBS

How can I get a NOE in the following code?

[code]Private Sub GetListOfFiles(StartFolderitem as FolderItem)

if StartFolderitem = nil then return

dim theFileList as new FileListMBS(StartFolderitem)
dim FileCount as Integer = theFileList.Count - 1
for currentFile as Integer = 0 to FileCount

if theFileList.Item(currentFile) <> Nil and theFileList.Visible(currentFile) then
  if theFileList.Directory(currentFile) then
    GetListOfFiles theFileList.TrueItem(currentFile)
  else
    dim FileEnding as String = theFileList.TrueItem(currentFile).NameExtensionMBS
    if FileEnding = "pdf" then 
      dim theAuthor as String = GetPDFAuthor(theFileList.TrueItem(currentFile))
      MessageIDs.Value(theAuthor) = theAuthor
    end if
  end if
end if

next

End Sub[/code]

From the stacktrace

2018-06-09, 1:22:12 Class/Method: WriteMessageToPDF.GetListOfFiles
2018-06-09, 1:22:12 Time: 2018?6?9? ??? 1:22:12 10078638
2018-06-09, 1:22:12 Type of Error: NilObjectException
2018-06-09, 1:22:12 --------------------------
2018-06-09, 1:22:12 Stack:
2018-06-09, 1:22:12
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)
Sub WriteMessageToPDF.GetListOfFiles(FolderItem)

the error occurs pretty deep into the folder hierarchy.

The only thing that could make a difference is the use of .Item instead of .TrueItem when doing the Nil check here:

theFileList.Item(currentFile) <> Nil

Any other ideas?

Xojo 2017r1 on macOS 10.13.5.

you may want to use theFileList.TrueItem(currentFile) once and store that in a variable.
Than use it instead of calling this function so often. Also you can change to check that with nil.

Also FileListMBS doesn’t raise nil object exception on itself, only OutOfMemoryExceptions if needed.

Thanks, Christian, I’ll try your idea and report back.