Commits


Adam Szmigin authored and Eric Erhardt committed 0cf54bf1c61
ARROW-8886: [C#] Resize to negative length no longer permitted The C# implementation of buffer builders previously accepted a negative length to the `Resize()` method, and clamped it to zero. However, based on [comments by the original author of that code](https://github.com/apache/arrow/pull/7158#discussion_r437589084) @chutchinson , this behaviour is being changed to disallow negative lengths: > It's hard to say why I chose this behavior; this was written over a year ago. I can only imagine my thought process was that the capacity "can't go any lower", and avoiding the costs that come with throwing an exception. > > The unit test existed to verify the behavior as written, not necessarily to satisfy requirements, which I would agree was misguided. > > My current stance would be to match the behavior of the more mature implementations, and throw **ArgumentOutOfRangeException**. I tend to prefer avoiding exceptions and bounds checking where possible, but as a consumer I could understand being surprised to find that passing a negative capacity results in an empty buffer. I'm not sure I would expect this method in a situation where the bounds checking or exception stack unwinding would be harmful enough to be undesirable. The new behaviour is in line with the [behaviour in the C++ Arrow implementation](https://github.com/apache/arrow/blob/master/cpp/src/arrow/array/builder_base.h#L190), and library functions like [`System.Array.Resize<T>()`](https://docs.microsoft.com/en-us/dotnet/api/system.array.resize?view=netcore-3.1). Closes #7657 from mr-smidge/arrow-8886/resize-negative-length-not-permitted Authored-by: Adam Szmigin <adam.szmigin@jetstoneam.com> Signed-off-by: Eric Erhardt <eric.erhardt@microsoft.com>