mr-smidge opened a new pull request #7657: URL: https://github.com/apache/arrow/pull/7657
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 indeed library functions like [`System.Array.Resize<T>()`](https://docs.microsoft.com/en-us/dotnet/api/system.array.resize?view=netcore-3.1). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
