Bug In `File.ReadText()`?

I have this C# code in a macOS Island console application using RTL:

    static class Program
    {
        public static Int32 Main(string[] args)
        {
            string filePath = "/Users/garry/Desktop/test.possum";
            if (File.Exists(filePath))
            {
                Console.WriteLine("File exists");
                string s = File.ReadText(filePath);
                Console.Write(s);
            }
        }
    }

The console prints out “File Exists” but then the app crashes with this message:

~> Process Test macOS App started
File exists
~> Ignored exception of type RemObjects.Elements.System.Exception on thread 380A
~> Message: Array index 0 is outside of the valid range (array is empty)
Uncaught exception: RemObjects.Elements.System.IndexOutOfRangeException: Array index 0 is outside of the valid range (array is empty)
~> Process Test macOS App terminated with exit code 255. Ran for 2.069

At first I thought it might be because I hadn’t supplied an encoding to the ReadText() method but the same crash happens with File.ReadText(filePath, Encoding.UTF8) too.

Where’s the array index issue? I’m assuming it’s in RTL somewhere?

Here’s the contents of the file (if it makes a difference):

var x = "global"
function outer():
	var x = "outer"
	function inner():
		print x;
	inner()

outer()

Unfortunately I cannot easily test this issue myself right now, because I have the same Island RTL issue you encountered on the there thread (and not the time t work around that, right now).

I assume this is with your manually rebuilt Island RTL, correct?

Does this exception break into the debugger for you? Do you get a call stack for the exception there?

It’s using the freshly build Island RTL workaround from the repo that I built on 10.15.5, correct.

The exception doesn’t break into the debugger. No call stack that I can see.

The app just terminates with this in the console:

There’s two bugs here.

First one is fixed, if you pull latest Island RTL. Turns out that

method MemoryStream.ToArray: array of Byte;
begin
  result := new array of Byte(fLength);
  memcpy(@result[0], @fbuf[0], fLength);
end;

fails on an empty array, because [0] is out of range ;).

The second bug is that the binary is empty; I’m still investigating that one.

Ah yes, it seems you have set Fire to ignore this exception type ;). You can reset that under Debug|Manage Exceptions.

Thanks, logged as bugs://84560 — for ReadBinary returning empty on Island.

Thanks for getting to the bottom of things @mh. Don’t give up your Sunday free time though!

1 Like

No worries, gonna head down to the beach and do some diving in a bit :wink:

2 Likes

bugs://84560 got closed with status fixed.